Sending Parts:
For var = i To x
Dim PACKET_SIZE As UInt16 = 4096
Dim ByteArray() As Byte ' Data buffer
filestream = New FileStream(at(z), FileMode.Open, FileAccess.Read)
Reader = New BinaryReader(filestream)
Writer = New BinaryWriter(clientSocke.GetStream) ' Get socket's stream
'send size of file
Writer.Write(CInt(filestream.Length))
'Send the file data
Do
'read data from file
ByteArray = Reader.ReadBytes(PACKET_SIZE)
'write data to Network Stream
Writer.Write(ByteArray)
Loop While ByteArray.Length = PACKET_SIZE
'make sure all data is sent
Writer.Flush()
z = z + 3
Next
NOTE : at(z) ---> arrayteks that's save filepath
Receiving Parts:
For var = i To x
Dim PACKET_SIZE As UInt16 = 4096
Dim Reader As BinaryReader
Dim ReadBuffer(PACKET_SIZE - 1) As Byte
Dim NData As Int32
Dim MStream As MemoryStream
Dim LData As Int32
Reader = New BinaryReader(clientSocket.GetStream)
' Read Length of data (Int32)
NData = Reader.ReadInt32
MsgBox(NData.ToString)
' Now comes the data, save it in a memory stream
MStream = New MemoryStream
While NData > 0
LData = clientSocket.GetStream.Read(ReadBuffer, 0, PACKET_SIZE)
MStream.Write(ReadBuffer, 0, LData)
NData -= LData
probar += 1
BackgroundWorker1.ReportProgress(probar)
Threading.Thread.Sleep(100)
End While
probar = 100
BackgroundWorker1.ReportProgress(probar)
Threading.Thread.Sleep(100)
SaveFile(arrayTeks(z), MStream.ToArray, False) 'Then
z = z + 3
probar = 0
BackgroundWorker1.ReportProgress(probar)
Next
NOTE: arrayteks(z) ----> file path that I use to save received picture file
problem :
I successfully received the 1st picture file, but, when it comes the 2nd picture mu program start to have an infinite loops...
any Idea ???
thanks before...