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

From: CHRISM (chris_at_sorry.no.spam.com)
Date: 11/12/04


Date: Thu, 11 Nov 2004 20:23:01 -0500


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

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



Relevant Pages

  • Re: Forwarding Web server requests to local machine
    ... The problem is that ssh listens on all IPs that are on the same network ... listenying to port 80, so ssh fails to listen on port 80. ... ML> connected by a remote server that I do not control (actually ... ML> thought of using ssh to forward port 80 connections to that remote ...
    (comp.security.ssh)
  • Too many open files
    ... I am writing an application server using TCP server which can only ... accept upto 249 client connections. ... I run my server in Windows XP. ... process to support 5000 connections. ...
    (comp.lang.ruby)
  • Re: Socket Server question
    ... > If I have a Socket Server where clients establish new socket ... > connections, and one of the client connections is prematurely disconnected, ...
    (comp.lang.pascal.delphi.misc)
  • Socket Server question
    ... If I have a Socket Server where clients establish new socket ... connections, and one of the client connections is prematurely disconnected, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Telnet Programming
    ... if you write the application so that it listens for incoming ... connections. ... that port (Ports from 1 to 1024 are usually not allowed to use by normal ... documentation about sockets and how to create a server to listen them. ...
    (comp.programming)

Loading