|
-
October 6th, 2004, 02:21 AM
#1
Winsock: listen and backlog-parameter
Could someone explain me the backlog-paramter in the listen-function in winsock2?
-
October 6th, 2004, 02:44 AM
#2
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.
-
October 6th, 2004, 02:58 AM
#3
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?
-
October 6th, 2004, 03:14 AM
#4
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.
-
October 6th, 2004, 03:19 AM
#5
Re: Winsock: listen and backlog-parameter
Ah, now I understand. Thanx a lot!!
-
October 6th, 2004, 11:46 AM
#6
Re: Winsock: listen and backlog-parameter
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|