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.IAsyncRe sult)
'Get Server Socket
Dim theServerSocket As Socket = CType(ar.AsyncS tate, Socket)
'Accept Connection
Dim theClientSock As Socket = theServerSocket .EndAccept(ar)
'Set Linger Option
Dim lingerOptionVal ue As New LingerOption(Tr ue, 30)
theClientSock.S etSocketOption( SocketOptionLev el.Socket, _
SocketOptionNam e.Linger, lingerOptionVal ue)
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.S end(theBytes)
Next
theClientSock.C lose()
End Sub
///////////////////////////////////////////////////////////////////