Problem with CSocket
-
I'm trying to figure out why my
CSocket.Receive()
call is blocking. This is the code I have so far:CSocket socket; //Connect to server socket.Create(); ret = socket.Connect(m_sAddress, m_nPort); //Check for connection errors if (ret == 0) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (ret == 0)__ m_TotalBytes = 0; while(m_bRunThread) { BYTE* pBuffer = new BYTE[MAX_BUFFER_SIZE]; ret = socket.Receive(pBuffer, MAX_BUFFER_SIZE); ........ }
The socket connects but never receives any data. The call to Receive seems to block the thread. I know the server program I am using is working because I can transfer data to other clients without a problem. Any suggestions? Thanks -
I'm trying to figure out why my
CSocket.Receive()
call is blocking. This is the code I have so far:CSocket socket; //Connect to server socket.Create(); ret = socket.Connect(m_sAddress, m_nPort); //Check for connection errors if (ret == 0) { GetSocketError(); //Get Socket's Last Error return -1; } //__if (ret == 0)__ m_TotalBytes = 0; while(m_bRunThread) { BYTE* pBuffer = new BYTE[MAX_BUFFER_SIZE]; ret = socket.Receive(pBuffer, MAX_BUFFER_SIZE); ........ }
The socket connects but never receives any data. The call to Receive seems to block the thread. I know the server program I am using is working because I can transfer data to other clients without a problem. Any suggestions? ThanksUse CAsyncSocket instead of CSocket. CSocket assumes synchonous communications (that is, you will send, then wait for a return message). An alternative is to put the socket's receive call in a worker thread that fires off an event when it receives data in the buffer. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac