Sockets App

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
 
C

Craig Vick [MSFT]

Hi Chad,

You may want to try looping while numberOfBytesRead > 0 for troubleshooting
purposes. Here's a reference with an example.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnetsocketssocketclassreceivetopic.asp

Craig, VB.NET Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
Content-Class: urn:content-classes:message
From: "Chad" <[email protected]>
Sender: "Chad" <[email protected]>
Subject: Sockets App
Date: Mon, 6 Oct 2003 06:44:08 -0700
Lines: 46
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcOMD+qjtHuv/kWZQ/C/84yqikiWaw==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:144162
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top