[HELP]sending many picture using socket programming

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 46
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

[HELP]sending many picture using socket programming

 
0
  #1
Aug 26th, 2009
i'm try to send many picture using socket programming in VB 2005 from client to server. but, after i run the program, only the first picture that reach destination server. and there is an error saying that my socket are no longer connected after the first picture are sent.

client side : ---> sender
at(0) -----> number of file that I want to send
at(3) n at(6) -----> file name address that I want to send
  1. i = 1
  2. Dim x As Integer
  3. Dim z As Integer = 3
  4. If at(3) <> Nothing And at(6) <> Nothing Then
  5. x = at(0) + 1
  6. For var = i To x
  7. Dim PACKET_SIZE As UInt16 = 4096
  8. Dim ByteArray() As Byte ' Data buffer
  9. Dim filestream As FileStream = New FileStream(at(z), FileMode.Open, FileAccess.Read)
  10. Dim Reader As New BinaryReader(filestream)
  11. Dim Writer As New BinaryWriter(clientSocke.GetStream) ' Get socket's stream
  12. 'send size of file
  13. Writer.Write(CInt(filestream.Length))
  14. 'Send the file data
  15. Do
  16. 'read data from file
  17. ByteArray = Reader.ReadBytes(PACKET_SIZE)
  18. 'write data to Network Stream
  19. Writer.Write(ByteArray)
  20. Loop While ByteArray.Length = PACKET_SIZE
  21. 'make sure all data is sent
  22. Writer.Flush()
  23. z = z + 3
  24. Writer.Close()
  25. Reader.Close()
  26. Next
  27. end if


Server side : ------> receiver
arrayteks(0) -----> number of file that I want to receive
arrayteks(3) n arrayteks(6) -----> file name address where I want save the received file
  1. Dim x As Integer
  2. Dim z As Integer = 3
  3. If arrayTeks(3) <> Nothing And arrayTeks(6) <> Nothing Then
  4. x = arrayTeks(0) + 1
  5. For var = i To x
  6. Dim PACKET_SIZE As UInt16 = 4096
  7. Dim Reader As BinaryReader
  8. Dim ReadBuffer(PACKET_SIZE - 1) As Byte
  9. Dim NData As Int32
  10. Dim MStream As MemoryStream
  11. Dim LData As Int32
  12.  
  13. Reader = New BinaryReader(clientSocket.GetStream)
  14. ' Read Length of data (Int32)
  15. NData = Reader.ReadInt32
  16. ' Now comes the data, save it in a memory stream
  17. MStream = New MemoryStream
  18. While NData > 0
  19. LData = clientSocket.GetStream.Read(ReadBuffer, 0, PACKET_SIZE)
  20. MStream.Write(ReadBuffer, 0, LData)
  21. NData -= LData
  22. End While
  23.  
  24. SaveFile(arrayTeks(z), MStream.ToArray, False) 'Then
  25. z = z + 3
  26. Next
  27. end if

many thanks before...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 270
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 54
GeekByChoiCe GeekByChoiCe is offline Offline
Posting Whiz in Training

Re: [HELP]sending many picture using socket programming

 
0
  #2
Aug 27th, 2009
you shouldnt close the writer (which is your socket.getstream) inside the loop. that closes the connection
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 46
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [HELP]sending many picture using socket programming

 
0
  #3
Aug 29th, 2009
if so, then when I should close the connection ??
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 270
Reputation: GeekByChoiCe is on a distinguished road 
Solved Threads: 54
GeekByChoiCe GeekByChoiCe is offline Offline
Posting Whiz in Training

Re: [HELP]sending many picture using socket programming

 
1
  #4
Aug 29th, 2009
declare the reader and writer before the for loop, assigne the values inside the loop and close them after the loop
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 46
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [HELP]sending many picture using socket programming

 
0
  #5
Aug 30th, 2009
thanks. try i'll that
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 46
Reputation: murid is an unknown quantity at this point 
Solved Threads: 1
murid murid is offline Offline
Light Poster

Re: [HELP]sending many picture using socket programming

 
0
  #6
Sep 2nd, 2009
now i can send many picture...
thanks...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 486 | Replies: 5
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC