I have created a Dialog application. Acting as Server. And if I click a button the server will start listening for connections from the client.
When I click the button to start listening ,
(I am using the normal socket functions), so after issuing accept the dialog app hangs. So I modified the code in such a way that the socket call for accept does not block using the ioctl socket function on listening socket.
Now the dialog app did not hang.
My problem is , when I tried to connect with the client the connect is successful but the server side cannot accept the incoming connection instead I got an error when I used GetLastError as following:
"A non-blocking socket operation could not be completed immediately."
I want to know how should I able to achieve connection (or) How should I make the accept call succeeded.
/*************************************************/
Here is the part of Server code:
//bind the socket id to the local address
if (bind(listenSocket,(struct sockaddr *) &WdxAddress, sizeof(WdxAddress)) == SOCKET_ERROR)
{
}
if (listen(listenSocket, 100) == SOCKET_ERROR)
{
}
Can anybody help me in this regard?????
I dont want my Server Dialog app to be hanging until there is a connection is made by the client. Because I want to do some other tasks also with the dialog app meanwhile waiting for connections.
You could run the blocking system calls in another thread. That way your dialog thread still runs and your networking thread sleeps until something happens on the network.
Another approach (if you're running a os that supports signals) is to use asynchronous io and set up a signal handler for the SIGIO signal and do the networking from that handler.
If you try and take a cat apart to see how it works,
the first thing you'll have on your hands is a nonworking cat
Now I am using the thread to listen for the incoming connections. So my dialog app is having no problem. It can respond , meanwhile waiting for connection from client.
Is this the preferred method for setting a socket to non blocking? I've added it to my code and it errors. Any ideas? Everything works fine as a blocking socket.
Bookmarks