C
Chad
I have developed a Sockets application using .NET Sockets.
The only problem I have with my application is that it
will sometimes lose part of the TCP/IP Message. The
message I am sending is 963 Bytes long.
My buffer is set at 4096 Bytes. The application will
always receive the entire message when I test it local. If
I put the server piece on another machine and connect to
it with my TeraTerm client it will randomly lose half of
the message. If I use my client that I develop with the
Winsock Control in Visual Basic 6 it will never lose part
of the message. It appears that the TeraTerm Client sends
out 100 Bytes at a time and the other client application
sends the whole message which is 963 Bytes. Also, I'm
using a synchronous server socket because this is a simple
network application. Why does this occur? Is it a
buffering problem? Listed below is the code I am using to
read from the socket.
'Determine if the NetworkStream is readable.
If socketStream.CanRead Then
'******************************************************
The application will sit in this loop until
it receives a message since I am using a
synchronous server socket.
'*****************************************************
Do
'Read the TCP/IP Message into the buffer
numberOfBytesRead = socketStream.Read
(myReadBuffer, 0, myReadBuffer.Length)
'Convert the Byte Array to a String
sTmpMessage = [String].Concat(sTmpMessage,
Encoding.ASCII.GetString(myReadBuffer, 0,
numberOfBytesRead))
'Client Shutdown the TCP/IP Socket if Number of Bytes Read
Equal Zero
If numberOfBytesRead = 0 Then
bDisconnected = True
End If
Loop While socketStream.DataAvailable
End If
The only problem I have with my application is that it
will sometimes lose part of the TCP/IP Message. The
message I am sending is 963 Bytes long.
My buffer is set at 4096 Bytes. The application will
always receive the entire message when I test it local. If
I put the server piece on another machine and connect to
it with my TeraTerm client it will randomly lose half of
the message. If I use my client that I develop with the
Winsock Control in Visual Basic 6 it will never lose part
of the message. It appears that the TeraTerm Client sends
out 100 Bytes at a time and the other client application
sends the whole message which is 963 Bytes. Also, I'm
using a synchronous server socket because this is a simple
network application. Why does this occur? Is it a
buffering problem? Listed below is the code I am using to
read from the socket.
'Determine if the NetworkStream is readable.
If socketStream.CanRead Then
'******************************************************
The application will sit in this loop until
it receives a message since I am using a
synchronous server socket.
'*****************************************************
Do
'Read the TCP/IP Message into the buffer
numberOfBytesRead = socketStream.Read
(myReadBuffer, 0, myReadBuffer.Length)
'Convert the Byte Array to a String
sTmpMessage = [String].Concat(sTmpMessage,
Encoding.ASCII.GetString(myReadBuffer, 0,
numberOfBytesRead))
'Client Shutdown the TCP/IP Socket if Number of Bytes Read
Equal Zero
If numberOfBytesRead = 0 Then
bDisconnected = True
End If
Loop While socketStream.DataAvailable
End If