To all you socket veterans out there
-
Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|
-
Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|
-
Can someone please tell me a tried and true method for listing (from a client app, not a server) to a socket without hanging the entire program. I'm trying to detect when data arrives without having to continually probe the socket and without locking up the main app by blocking. There's CAsyncSocket & CSocket (MFC) that uses messaging, there's raw sockets, I guess I could create a new thread that performs a while loop and blocks on the call to recv(...) - should I use non-blocking I/O schemes - should I use winsock or winsock2, ... I'm a little overwhelmed and maybe I've made it harder than it should be. Any clarification is much appreciated. :confused: X|
If your starting out, I'd just use the MFC CSocket class. Get a simple client and server working with CSocket and then get complicated (i.e. asychronous) later. Override the OnReceive(...) message. When data shows up, OnReceive will get called, so then you call Receive(...) to receive the data. If there is more data in the buffer, OnReceive will get called again for you. I don't know if the socket calls are blocking or not, but CSocket works synchronously rather than asynchronously, which will save you a lot of headaches. In my experience, the CSocket Connect() call is annoying when it blocks, but the Receive() and Send() calls are barely noticable when you call them. Remember that we're going at network speed, dude, and we know that the data has already arrived via TCP/IP. All you have to do is read it out of memory. "Harland Pepper, would you stop naming nuts" - Harland Pepper