Advertisement

Telnet Help

Started by December 05, 2003 01:54 PM
2 comments, last by AsciiFish 21 years, 2 months ago
I''m writing a program, a MUD to be specific, to send data to telnet clients. However, I get broken pipe errors when I try to send data to a client that has closed the connect. I''m having trouble detecting(accuratly) when a player has either closed the socket or been disconnected. Here is my function, please tell me what''s wrong. thanks. int CPlayer::sendToPlayer(string msg) { int count = 0, result=0, iBuff; string substring; char *a = new char; do { iBuff = recv(socketfd, a, sizeof(a), MSG_PEEK); if(iBuff==-1 && errno!=EAGAIN) { //check for bad connection cout << "connection problem" << endl; return 0; } else if(iBuff==0) { //check for graceful disconnection cout << "disconnected" << endl; return 0; } substring = msg.substr(count, msg.length() - count); result = send(socketfd, substring.c_str(), sizeof(substring.size()), 0); if(result==-1 && errno!=EAGAIN) { return 0; } if(result==-1) return 0; count+=result; }while(count<msg.length()); return 1; } Any help would be beyond appreciated. Thanks again
/*Joe DiMichele C/C++/VB Programmer, A+ Certified Technician AIM:Krawling Khaos, ICQ:332871787 joedimichele@hotmail.com oderint dum metuantExcuse my spelling, programmers can't spel*/
recvfrom returns SOCKET_ERROR if there''s something wrong, you can then get the actual error with WSAGetLastError
---Yesterday is history, tomorrow is a mystery, today is a gift and that's why it's called the present.
Advertisement
SOCKET_ERROR is winsock specific and since he''s getting a broken pipe I''m pretty sure he''s on a unix box.
Anyway recv returns zero when the connection has been closed, and if you are having problems with broken pipes why not just install a signal handler and ignore it?
I suppose i should have mentioned that i''m using BSD, so winsock stuff doesn''t help me much, but thanks. I''m new to unix programming, could you point me to a tutorial on signal handling?

Thanks.
/*Joe DiMichele C/C++/VB Programmer, A+ Certified Technician AIM:Krawling Khaos, ICQ:332871787 joedimichele@hotmail.com oderint dum metuantExcuse my spelling, programmers can't spel*/

This topic is closed to new replies.

Advertisement