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

C

CHRISM

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.Socket, _
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


///////////////////////////////////////////////////////////////////
 
C

CHRISM

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
 

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