| pa.chidhambaram wrote:|
I have tried to create chat application in VC++ 6.0. i have placed a thread for listening client request in server program. After a single sending process. the server cannot receive the client data. i used CSocket class to create a socket. And i want to know which method, is better one. 1) Using Threads or 2) By capturing events.
Multi-threading generally introduces un-intuitive complexity you don't want to deal with unless you've got the necessary insight. You should keep the application single-threaded, and e.g. do polls on the socket to see if there's data available for reading. If there's new data; display it, otherwise keep handling GUI notifications (or send new data to the other side).
One alternative way of handling socket events without more than one thread, is to use WSAAsyncSelect (http://msdn2.microsoft.com/en-us/library/ms741540.aspx). That enables you to receive window messages e.g. when data arrives. It's generally not as efficient as overlapped IO, but granted that this application will only transport chat messages, WSAAsyncSelect should provide a good combination of speed, flexibility and ease of use.