the recieve buffer is too big and the process is terminating before the client can supply the next block of data
try this
Function ReceiveData(ByVal skt As Socket) As MemoryStream
'create a memorystream to hold the incoming data
Dim ms As New MemoryStream
While True
'refresh the buffer
Dim buf = New Byte(1023) {}
'recieve some data
Dim br = skt.Receive(buf, buf.Length, SocketFlags.None)
'write the data into the memorystream
ms.Write(buf, 0, br)
'if the number of bytes is smaller than the buffer capacity we're at the end of the stream
If br < buf.Length Then Exit While
'give the client a chance to send more data (10 milliseconds)
Wait(10)
End While
Return ms
End Function
Sub Wait(ByVal i As Integer)
Dim st As New Stopwatch
st.Start()
Do Until st.Elapsed.TotalMilliseconds > i
Application.DoEvents()
Loop
st.Stop()
st = Nothing
End Sub