views:

1169

answers:

6

I'm writing a GUI-based app in VB.net that talks to a LambdaMOO server via telnet, sends commands to display the object hierarchy, then parses the output and creates a visual representation of the object hierarchy.

So my question is: is there some kind of "telnet client" class for .NET to simplify the sending and receiving of data, or do I have to write my own using the socket API?

Does Mono have something like this?

Barring an easy solution, does anyone have a good tutorial they can point to for telnet client programming in VB.net?

+1  A: 

The telnet protocol is basically just the usual TCP protocol, with a bunch of optional stuff that you probably won't need to implement. So you'd open a socket and start sending and receiving data with the socket stream interface.

Give it a try with the regular socket API, you'll probably find that it's quite straightforward.

Greg Hewgill
also everything i saw on a quick search was a paid solution, so i agree. up
Scott M.
I started doing just what you suggested, but found some weirdness in the behavior of the API. I was hoping someone had coded out all the weirdness with a higher-level "telnet client" class, so I don't have to learn the quirks of sockets or the quirks of telnet.I basically want to be able to script a telnet session with VB, and parse the returned data.
Mike
Perhaps you could describe the "weirdness" you're encountering and somebody will be able to point you in the right direction. Telnet is one of the simpler network protocols, so any problem you encounter will probably show itself somewhere else too. It's worth it to spend the time to understand how common levels like the socket API work.
Greg Hewgill
To give you a sneak preview: when I do a NetworkStream.Read() it only gives me the first line of output from the server, rather than all the output (my server sends twelve lines of text as soon as you connect to it). Yes, my buffer is big enough to hold more than the first line.If I call NetworkStream.Read() a second time, it will get the rest of the output for me. Now before you tell me to put it in a loop, I already did that, just like the example code. Doesn't work. I have to call the .Read() once outside the loop.So that's the weirdness I'm referring to.
Mike
A: 

just a suggestion. you may try to program your vb application to execute an existing telnet application in batch mode.

here is the link for your reference. refer to 7.3 Using Plink in batch files and scripts. Hope it helps.

poh
A: 

You can grab one of any number of libraries to use. Here's one library:

LINK

For others try googling something along the lines of: library telnet mud .NET

Lastly, there are any number of opensource MUD/MOO/MUSH projects open at any time who are willing the share ideas and looking for people to help with projects.

A: 

I had my trials with telnet. You've to use tools like wireshark in conjuntion to figure out what commands needs to be initiated. I did find communicating with my unix box quite a challenge. For one thing you must know your telnet instructions. You might find it difficult to determined the state of the application - whether it is logged in or not innately. You'd have to formulate your own logic for it.

Another thing you'd have to do is parse the bytes returned by telnet into commands or instruction data i.e. you have to know if the bytes received is an instruction or some other thing it is trying to send you. Here is a ref that would come in handy.

First I suggest you start using the wireshark tool and get the communications send to and fro manually as well as via application.

deostroll
Nice ref. Thanks.
Mike
A: 

You could look at the Expect command this is a scriptable solution for running telnet, ftp etc on remote machines. You could then script expect to connect and retrieve the data.

This would take away all the complexity of managing the socket and the protocol.

Steve Weet
A: 

Ok, I had a similar issue and ignoring all security complications and the like, wanted to TELNET from a VB initiated connection to a remote device and do stuff. I concur that the whole negotiation process is a hellish thing to do but once you've worked it out it's actually pretty simple to implement. I decided not to stop because I kept reading things that said it couldn't be done when it clearly can be done if you can write and read 1's and 0's into/from a network stream.

The code in the link below will initiate the connection and get you through to actually exchanging clear text information over TELNET. Given the example of sending a username and password combo shows how to read and write to the connection.

Big tips - initially have a nice big textbox or something to trap everything that comes into the buffer (variable returndata). This will help you diagnose problems. Also check on my blog there how to do this without the textbox blinking like a flashing thing. Once you've done all that and you know your script is reliable, trun off any screen updates and it will whizz through rather than take an age.

Apologies for the really dirty code and the crappy website layout.

http://myhead-online.blogspot.com/2009/05/vb-net2008-express-telnet-to-sun.html

Waldo