Hi,
I am listening to a port for data but I am not able to recieve whole
data, I only get truncated data. Client sends me data that exceeds 40K
and the data I recieve in my callback function is always 8K to 9K. I
dont get the rest of the data. I think the data size is too big to come
in one go and hence it comes in 2-3 sub-packages but my call back
function only gets called once hence I am getting truncated data. I am
sending the code...Is there anyway I can recieve complete data sent by
client
Public Function ConnecttSocket(byVal iPort as integer)
Dim _sHostName As String
Dim _iLocalPort As Integer = iPort
Dim LocalIp() As IPAddress
Dim _oIPHostEntry As IPHostEntry
Dim IPLocalEndPoint As IPEndPoint
oListenerSocket = New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
_sHostName = Dns.GetHostName()
_oIPHostEntry = Dns.GetHostByName(_sHostName)
LocalIp = _oIPHostEntry.AddressList()
IPLocalEndPoint = New IPEndPoint(LocalIp(0), _iLocalPort)
oListenerSocket.Bind(IPLocalEndPoint)
oListenerSocket.Listen(4)
oListenerSocket.BeginAccept(New AsyncCallback(AddressOf
onClientConnect), Nothing)
End Function
Private Sub onClientConnect(ByVal asyn As IAsyncResult)
Try
workerSocket = oListenerSocket.EndAccept(asyn)
SocketWaitForData(workerSocket)
oListenerSocket.BeginAccept(New AsyncCallback(AddressOf
onClientConnect), Nothing)
Catch ex As Exception
MessageBox.Show("onClientConnect " + ex.Message.ToString())
End Try
End Sub
Private Sub SocketWaitForData(ByVal soc As Socket)
Try
If SocketpfnCallBack Is Nothing Then
SocketpfnCallBack = New AsyncCallback(AddressOf SocketOnDataRcvd)
End If
result = soc.BeginReceive(SocketDataBuffer, 0, SocketDataBuffer.Length,
SocketFlags.None, SocketpfnCallBack, Nothing)
Catch ex As Exception
MessageBox.Show("SocketWaitForData " + ex.Message.ToString())
End Try
End Sub
Private Sub SocketOnDataRcvd(ByVal asyn As IAsyncResult)
Dim iRx As Integer = 0
Dim sSocketMessage As System.String
Try
iRx = workerSocket.EndReceive(asyn)
'iRx always shows 9K or 8K, I think this is the maximum capacity of
sockets to 'transfer data in one go
Dim chars(iRx + 1) As Char
Dim d As System.Text.Decoder = System.Text.Encoding.UTF8.GetDecoder()
Dim charlen As Integer = d.GetChars(SocketDataBuffer, 0, iRx, chars, 0)
sSocketMessage = New System.String(chars)
end sub