Receiving data from a mud with sockets - telnet negotiation?

466 views Asked by At

For a bit of context first, to make the question easier to understand: I've a fair understanding of java networking, but all networking I've done up to this point has been send a command-> wait for a response-> repeat. Recently I've been trying something in my spare time that's a bit different. I'd like to connect to a Mud, and I use a standard mud client. However, I got to thinking and decided I'd see if I could create a server which would then connect to the mud (so, I'd use my client to connect to the intermediate server, which would then connect to the mud proper). Mostly this was just to see if I could at first (a few friends and I wanted to set up outside game chat etc), but I've been encountering a few issues and now want to resolve them for future reference, since they seem fairly important.

So far, I set up a ServerSocket, accept a client connection, generate BufferedReaders/PrintWriters to hold input and output streams (inside a thread for each new connection). I then generate a second thread inside that client thread to connect to the mud, which then constantly loops reading lines and outputting them to the output stream of the client thread. The client thread loops waiting for command input, and processes it.

I'm not sure if this approach is appropriate (as I mentioned, I've never done Socket programming where input and output had to be handled at the same time). The main problem is that the output simply stops after a few lines, though. The server connects to the mud fine, and it prints about 12 or so lines of a login screen (I can clarify this number if its important, double line spacing makes it questionable). I looked around and a few mentions in other questions mentioned needing to send a sequence of bytes (telnet negotiation? I'm not familiar with the term) to avoid similar problems, but I couldn't find much concrete information about the issue.

I'm fairly sure its a technicality I'm not aware of, but if anyone could point me to some resources or supply a general solution or such, that'd be great.

1

There are 1 answers

0
Bo Zimmerman On

If I understand correctly, you are using a standard MUD Client to connect to a MUD via an intermediary/proxy server that you wrote.

And again, to make sure I'm on the same page: Each connection to your proxy spawns two threads: one which gathers bytes sent by the Client and forwards them to the MUD, and another which gathers bytes sent by the MUD and forwards them to the client.

Your problem:

Your client only see a limited number of bytes from the MUD.

Theories:

Your Telnet-Negotiation theory is a decent one. You need to be sending unmolested octets between the Client and the MUD, but a PrintWriter is designed to only send handle encoded text streams. This could scramble some of the non-ASCII bytes travelling back and forth through your proxy.

As I've been doing something similar recently, I would also like to throw out there the possibility of a buffer overrun happening. If each of your proxy threads is in a tight read-write loop, it's unlikely, but I was seeing the exact same thing you were because I was polling periodically and writing to buffers which were too small to handle the load.