I just tried to write my first tiny example using CC++ sockets.
Setting up the server and accepting new connections works fine.
But I have problems getting the data of clients, because I don't know how to detect if there are new data.
This is my current code:
_tcpstream is an object of type tcpstream.
string input; while(_tcpstream.isPending( SOCKET_PENDING_INPUT, 20 )) { if(_tcpstream.eof()) { cout << "End of file detected" << endl << flush; break; } else { _tcpstream >> input; _tcpstream << "user entered " << input << endl; cout << "user entered " << input << endl; } }
The isPending() call always returns true after the client first sent some data. eof() is false. So the code goes to the call of
_tcpstream >> input;
Which blocks until there is new data.
Can you help me? How do I detect there is really new data?
Log in to post a comment.
I just tried to write my first tiny example using CC++ sockets.
Setting up the server and accepting new connections works fine.
But I have problems getting the data of clients, because I don't know how to detect if there are new data.
This is my current code:
_tcpstream is an object of type tcpstream.
string input;
while(_tcpstream.isPending( SOCKET_PENDING_INPUT, 20 ))
{
if(_tcpstream.eof()) {
cout << "End of file detected" << endl << flush;
break;
} else {
_tcpstream >> input;
_tcpstream << "user entered " << input << endl;
cout << "user entered " << input << endl;
}
}
The isPending() call always returns true after the client first sent some data. eof() is false. So the code goes to the call of
_tcpstream >> input;
Which blocks until there is new data.
Can you help me? How do I detect there is really new data?