Click to See Complete Forum and Search --> : Send() and Sendto() problem


ccubed
July 1st, 2007, 12:44 PM
Okay, I have a really strange problem sending data over my socket. I can receive data fine, but i've come to notice that what I always thought was a recv problem has actually been a send problem. It doesn't get any errors when I send data and it appears to send it, but it seems as if the server doesn't get any of it. For example, When I connect my client to mud.shatteredequinox.com port 6666 the first thing I receive is this question.


Does your client support the ANSI Colour standard?(Y/N)


Now, I type n and it says it sends it but instead of going on to the screen that asks for my username(i've played here before so I know exactly what's next), it just displays the message again, the same as if I had pushed enter and sent nothing. Currently, I use a std::string and the c_str() function to send the data over a sock_stream. Is there any reason that this would be happening?

MikeAThon
July 2nd, 2007, 06:31 PM
Many of your questions come down to the same thing: What is the protocol used by the mud server?

You need to find out the protocol and then follow it in sending and receiving. For example, on sending data to the server, how is the data sent? Null-terminated? CR-LF terminated? Length-prefixed?

Mike

ccubed
July 3rd, 2007, 03:48 AM
Well, I currently use SOCK_STREAM with no real protocol.

My socket call is socket( nova, SOCK_STREAM, 0 );

I suppose i could try IPPROTO_TCP.

MikeAThon
July 3rd, 2007, 11:25 AM
SOCK_STREAM is the transport layer protocol (i.e., it's TCP); it's not the application layer protocol.

You need to determine the application layer protocol, which sits on top of the transport layer protocol. For example, HTTP is the application layer protocol that sits on top of TCP, and which is used by all web browsers and web servers to deliver Internet content.

The transport layer gets data from the sender to the recipient, but assigns no meaning to the data. The application layer is responsible for explaining what the data means, and how to interpret what's received.

Googling shows that MUD uses the telnet protocol. See "Everything You Wanted To Know About Mud Client/Server Interaction But Were Afraid To Ask" at http://cryosphere.net/mud-protocol.html . This means that you will need to read RFCs 854 and 855, which specify telnet:
http://www.faqs.org/rfcs/rfc854.html
http://www.faqs.org/rfcs/rfc855.html
Apparently, MUD does not use telnet negotiation, so your client should respond to all such requests with a "WONT" telnet repsonse.

Telnet is basically text delimited by a carriage return/line feed pair (CRLF). After every transmission from your client, you must send a CRLF pair. Is your client doing this? Show your sending code.

Mike

ccubed
July 4th, 2007, 06:57 PM
bool send_data(){

if ( sizeof(out) != 0 ){

out += "\n\r";

datasize = sendto( Nova, out.c_str(), sizeof(out), 0, (SOCKADDR*) &sin, sizeof(sin) );

if ( datasize == SOCKET_ERROR ){

#ifdef DEBUG
std::cout << "#DEBUG: ERROR SENDING DATA. Error " << WSAGetLastError() << " returned." << std::endl;
#endif

return false;

}
else{

#ifdef DEBUG
std::cout << "#DEBUG: " << datasize << " Bytes sent." << std::endl << "#DEBUG:SENT: " << out << " . " << std::endl;
#endif

return true;

}

}
else{

#ifdef DEBUG
std::cout << "DEBUG:NO DATA IN OUT." << std::endl;
#endif
std::cout << "#Nothing to send. Try typing something." << std::endl;

}


}

After i changed it to add "\n\r" to out it gets past the first part, but now whenever I type in my name at the login screen it just gets stuck. It does this on any mu*.

MikeAThon
July 4th, 2007, 09:19 PM
Add "\r\n", not "\n\r" (i.e., CRLF not LFCR).

As for the rest, I don't know the telnet protocol. You need to read the rfc's or read a telnet tutorial. Here's a short one, found by Googling: http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html

Mike