M
Mobile Boy 36
Hello group,
I use sock.available to determine the number of bytes on the network buffer.
This works fine if I only use sock.receive...
From the moment, one call to sock.send has been made, sock.available returns
1.
Here 's my code snippet...
Does a workarround exist?
Best regards
Private Function PakketCyclus() As Boolean
Dim bytesReceived() As Byte
Dim bytesToSendBack() As Byte
Dim NumberOfBytes As Integer
Dim ep As System.Net.IPEndPoint
Dim sock As System.Net.Sockets.Socket
Dim Result As Boolean = False
Dim AscIIEncoder As New System.Text.ASCIIEncoding
Dim Pakket As String
Dim PakketBuffer As Byte()
ep = New System.Net.IPEndPoint(_ServerIP, _Port)
sock = New
System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork,
Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
'sock.Blocking = True ' Maakt niet uit voor de serverkant
Try
sock.Connect(ep)
Pakket = "test"
PakketBuffer = AscIIEncoder.GetBytes(Pakket)
MsgBox(sock.Send(PakketBuffer, PakketBuffer.Length,
Net.Sockets.SocketFlags.None))
NumberOfBytes = sock.Available
While NumberOfBytes > 0
ReDim bytesReceived(NumberOfBytes)
sock.Receive(bytesReceived, 0, NumberOfBytes,
System.Net.Sockets.SocketFlags.None)
MsgBox(System.Text.Encoding.ASCII.GetString(bytesReceived, 0,
NumberOfBytes))
NumberOfBytes = sock.Available
End While
Result = True
Catch err As Exception
Result = False
End Try
sock.Close()
Return result
End Function
I use sock.available to determine the number of bytes on the network buffer.
This works fine if I only use sock.receive...
From the moment, one call to sock.send has been made, sock.available returns
1.
Here 's my code snippet...
Does a workarround exist?
Best regards
Private Function PakketCyclus() As Boolean
Dim bytesReceived() As Byte
Dim bytesToSendBack() As Byte
Dim NumberOfBytes As Integer
Dim ep As System.Net.IPEndPoint
Dim sock As System.Net.Sockets.Socket
Dim Result As Boolean = False
Dim AscIIEncoder As New System.Text.ASCIIEncoding
Dim Pakket As String
Dim PakketBuffer As Byte()
ep = New System.Net.IPEndPoint(_ServerIP, _Port)
sock = New
System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork,
Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
'sock.Blocking = True ' Maakt niet uit voor de serverkant
Try
sock.Connect(ep)
Pakket = "test"
PakketBuffer = AscIIEncoder.GetBytes(Pakket)
MsgBox(sock.Send(PakketBuffer, PakketBuffer.Length,
Net.Sockets.SocketFlags.None))
NumberOfBytes = sock.Available
While NumberOfBytes > 0
ReDim bytesReceived(NumberOfBytes)
sock.Receive(bytesReceived, 0, NumberOfBytes,
System.Net.Sockets.SocketFlags.None)
MsgBox(System.Text.Encoding.ASCII.GetString(bytesReceived, 0,
NumberOfBytes))
NumberOfBytes = sock.Available
End While
Result = True
Catch err As Exception
Result = False
End Try
sock.Close()
Return result
End Function