943,547 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1361
  • VB.NET RSS
Aug 26th, 2009
0

[HELP]sending many picture using socket programming

Expand Post »
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
VB.NET Syntax (Toggle Plain Text)
  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
VB.NET Syntax (Toggle Plain Text)
  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...
Similar Threads
Reputation Points: 21
Solved Threads: 1
Light Poster
murid is offline Offline
48 posts
since May 2009
Aug 27th, 2009
0

Re: [HELP]sending many picture using socket programming

you shouldnt close the writer (which is your socket.getstream) inside the loop. that closes the connection
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Aug 29th, 2009
0

Re: [HELP]sending many picture using socket programming

if so, then when I should close the connection ??
Reputation Points: 21
Solved Threads: 1
Light Poster
murid is offline Offline
48 posts
since May 2009
Aug 29th, 2009
1

Re: [HELP]sending many picture using socket programming

declare the reader and writer before the for loop, assigne the values inside the loop and close them after the loop
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Aug 30th, 2009
0

Re: [HELP]sending many picture using socket programming

thanks. try i'll that
Reputation Points: 21
Solved Threads: 1
Light Poster
murid is offline Offline
48 posts
since May 2009
Sep 2nd, 2009
0

Re: [HELP]sending many picture using socket programming

now i can send many picture...
thanks...
Reputation Points: 21
Solved Threads: 1
Light Poster
murid is offline Offline
48 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: update database when the website is nor running on the browser
Next Thread in VB.NET Forum Timeline: INSERTING RECORD IN THE DATABASE(sURNAME AND TEMPLATE)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC