-
What do you mean by 'two processes running at teh same time'. Do you mean your client and server run at the same time? If so just run each of them seperatly.
You dont' need threads for any of what you are doing and threads are quite complex and will only make things worse. Look up select as I already suggested, and please be more complete in what you mean by "two processes running at the same time".
-
You don't need to have 2 threads running for reading/sending. You can use non-blocking sockets for this. As orbitz explained above, threads are not necessary unless you need more processing done with other parts of your server. Honestly you shouldn't think of being multi-threaded until you can get the reading/writing w/o blocking.
If writing for windows, check out WSAAsyncSelect, or use Select() from
Beej's Guide . Orbitz is also right about defining what you mean, because from what I see, you want to run a server and client at the same time from the same app? Do you mean something else?
-
Another question on sockets.
Can you have a socket as a public object in a class?
Code:
class SocketProgram
{
public:
SocketProgram();
~SocketProgram();
SOCKET localSocket;
sockaddr_in localSockAddr;
};
-
Of course, why wouldn't you be able to?
-
and another question on sockets.
what is the scope of the sockaddr_in?
Once it has been declared, what scope does it have?
-
The same scope as any other variable. The scope rules do not apply special for sockaddr_in.