By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Sockets App

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/de...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" <cd*****@jackhenry.com>
Sender: "Chad" <cd*****@jackhenry.com>
Subject: Sockets App
Date: Mon, 6 Oct 2003 06:44:08 -0700
Lines: 46
Message-ID: <14****************************@phx.gbl>
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.