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

Server socket problem.. client sees connection close before all data received

P: n/a

Hiya,

Been trying to figure this one out. I've written a very simple server
in VB.NET that listens for client connections, then spits out a bunch
of text and then closes the connection. Much like an HTTP server
might do when you request a web page.

The server socket listens for connections using BeginAccept(); and
here's the simple handler function that gets called when a client
connects.

The Problem: I use TELNET from another machine to connect to the
server. I should see the numbers "1 2 3 4 ..." all the way up to
9000. But I usually get to only 5200 or sometimes into the 7000's
before telnet says "Connection to host lost."

I added a LingerOption, for 30 seconds, but that seems to have no
effect. I also tried enabling the "NoDelay" option and that seemed to
make no difference either.

Does anyone know what's going on and how to fix it?

Thanks,
// CHRIS


///////////////////////////////////////////////////////////////////

Public Sub SRV_SOCK_ACCEPT(ByVal ar As System.IAsyncResult)

'Get Server Socket
Dim theServerSocket As Socket = CType(ar.AsyncState, Socket)
'Accept Connection
Dim theClientSock As Socket = theServerSocket.EndAccept(ar)
'Set Linger Option
Dim lingerOptionValue As New LingerOption(True, 30)
theClientSock.SetSocketOption(SocketOptionLevel.So cket, _
SocketOptionName.Linger, lingerOptionValue)
Dim n As Integer 'Counter
Dim theBytes() As Byte 'Byte array for encoding text

For n = 1 To 9000
theBytes = Encoding.ASCII.GetBytes(String.Format("{0} ", n))
theClientSock.Send(theBytes)
Next

theClientSock.Close()

End Sub
///////////////////////////////////////////////////////////////////
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Thu, 11 Nov 2004 20:23:01 -0500, CHRISM <ch***@sorry.no.spam.com>
wrote:

<Running with Scissors>
Does anyone know what's going on and how to fix it?

Seems that TELNET isn't very graceful.. I tried the same test using a
program I wrote and it seems to work fine. The problem? TELNET,
apparently, halts when it senses a connection close. They way it
SHOULD work is that it should continue to receive until there is
nothing left to read. THEN close the connection and halt.

// CHRIS

Nov 21 '05 #2

P: n/a
On Thu, 11 Nov 2004 20:23:01 -0500, CHRISM <ch***@sorry.no.spam.com>
wrote:

<Running with Scissors>
Does anyone know what's going on and how to fix it?

Seems that TELNET isn't very graceful.. I tried the same test using a
program I wrote and it seems to work fine. The problem? TELNET,
apparently, halts when it senses a connection close. They way it
SHOULD work is that it should continue to receive until there is
nothing left to read. THEN close the connection and halt.

// CHRIS

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.