Hi
Im not sure if this post should be in this board or the network programming board, anyway here is my question.
I am coding a server program with sockets on linux and when I got to the recv part I noticed a unexpected behaviour.
Here is the code for the recv data part:
Now when I run this and connect to the server with telnet, the server waits until I press ENTER until it writes recvBuf to the screen. But if I press '.' the program ends without me pressing ENTER.Code://read some data char recvBuf; do { error = recv(new_fd, &recvBuf, 1, 0); switch (error) { case -1: cout << "[ERROR] recieving data" << endl; recvBuf = '.'; break; case 0: cout << "Connection to client was lost" << endl; recvBuf = '.'; break; default: cout << recvBuf; } } while (recvBuf != '.');
How can the text I type in telnet be saved and then printed, shouldn't the recvBuf be overwritten for every new data the server reads ?
Thanks for helping me understand this.



LinkBack URL
About LinkBacks


