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
///////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////