Groups | Blog | Home
all groups > dotnet compact framework > september 2005 >

dotnet compact framework : Weird sock.Available behavior


Mobile Boy 36
9/28/2005 11:13:15 AM
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

Mobile Boy 36
9/29/2005 5:08:10 PM
Hi group,

Scratch it...The day after I restarted Visual Studio and now everything
works fine
[quoted text, click to view]

AddThis Social Bookmark Button