HI all,

Please clarify this doubt. I have one client which is connecting to a server. In client there is one thread which is continuously receiving data from same socket and in main thread, I am trying to write data on that socket.

Does causes to race condition on that socket, because sometimes program is not at all responding.

Posted on 2004-03-09 00:49:26 by cult
Imagine the server socket automatically spawns a new socket when you call Accept... you have your one main Listening Server Socket which only job is to accept new connections... when you call Accept, you get a new hSocket, which is only for that server-client session, so each new client who connects to the server causes us to call Accept, and gives us yet another hSocket... I suggest you think about calling CreateThread in the Accept handler, and handing the new thread the return value from the call to Accept as your user param in the CreateThread call :) What this means is your "server session thread" is created once per client who connects, and has a unique hSocket handed to it, so each thread is a Worker which from there on runs alone.. if you are clever, you can use the hSocket values to identify the sessions when new socket messages arrive for these subordinate sockets. If you are not so clever, you may wish to try using my CServer and CClient Classes to handle all the dirty work for you, plus get your feet wet with OOPasm code.
Posted on 2004-03-09 04:42:29 by Homer
I suppose you didn't get my question correctly.

Please let me come again. I am not bother about, how the server is handling my session.

My problem is,

I have written a client which has two threads, main and another one is recvThread. I have opened a global socket.

Now, my recvThread is trying to read data from that socket and handing over to the main thread. In main thread I am doing some processing and then my main thread sending or writing back the processed data on that socket again.

So, is there is a race condition or synchronization problem on that socket.

Posted on 2004-03-09 05:01:18 by cult
You are right, I did not read your question correctly - in particular I missed the point about this being a pure Client.
There is no Race condition because your application is basically Stateful (since you do not process data until you receive it, and do not send replies until you process incoming data).
You should introduce a StateFlag within the Worker Thread, so that the main application can look up the state of the Worker and use it to synchronise events. This way, should you add more Client Threads, they will operate truly asynchronously.
This way, your Main Application becomes a "manager" of an array of worker threads who each own their own sockets.
Note there's no problem with associating multiple sockets to the same window if you insist on using WSAAsynchSelect... the wParam in WM_SOCKET messages will always = the hSocket of the session who created network noise, and can be used to look up the client in an array of structs since each owns a unique socket.
Posted on 2004-03-12 23:25:14 by Homer