CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Winsock: listen and backlog-parameter

    Could someone explain me the backlog-paramter in the listen-function in winsock2?

  2. #2
    Join Date
    Jan 2004
    Posts
    206

    Re: Winsock: listen and backlog-parameter

    From MSDN:

    The maximum length of the queue of pending connections. If this value is SOMAXCONN, then the underlying service provider responsible for socket s will set the backlog to a maximum "reasonable" value. There is no standard provision to find out the actual backlog value.

  3. #3
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Re: Winsock: listen and backlog-parameter

    Hi wombat, thanks for your reply. I found what MSDN says but I didn't understand it... Sorry, I'm new to winsocks. Perhaps I should explain what I want to do: I want to build a server with blocking winsocks (embedded in threads). To keep it simple in the beginning the server should just receiving and tracing text-msg which it receives from the clients.

    I do:
    1. Create a socket with socket()
    2. bind() the socket
    3. listen() to the socket
    4. accept() the connection -> acceptSocket
    5. recv from the acceptSocket

    My problem is: I don't understand how to receive multiple data. That means: While receiving another client could try to connect and si refused because the server is still receiving. How could this be handled?

  4. #4
    Join Date
    Jan 2004
    Posts
    206

    Re: Winsock: listen and backlog-parameter

    To solve your problem, after you accept each client connection, you can create a new thread to service that particular client request.

    Something like that:

    while(!Terminate)
    {
    // Accept new client connection

    // Create new thread to service new client request

    };

    In this case, the chances that multiple clients crashing with one another will be minimized. If new client do arrive when the server is creating new thread to service the current client's request, the new request would be placed in the queue automatically according to the backlog parameter. If the queue is already full, then the client request will be dropped. The client would receive an error from the connect() method, and may try to connect again at a later time.

  5. #5
    Join Date
    Aug 1999
    Location
    Germany
    Posts
    2,338

    Re: Winsock: listen and backlog-parameter

    Ah, now I understand. Thanx a lot!!

  6. #6
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: Winsock: listen and backlog-parameter

    Quote Originally Posted by mathro
    Could someone explain me the backlog-paramter in the listen-function in winsock2?
    To provide additional explanation…the listen() winsock call places your socket on a listen mode. Once it is on this mode, it can accept incoming connections on this interface and port. The actual connections are actually place on a queue (which is what is said in the MSDN ) and the backlog parameter signifies the length of the queue.
    The default value depends on the OS (5 for 9x and 200 for 2000) and it is recommended that the backlog value is set to SOMAXCONN. Even if you give a high no for the backlog parameter, this will be silently ignored (as said in the MSDN).

    Hope you understood what MSDN mean

    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured