Telnet Using C#

  • Thread starter Thread starter jtagpgmr
  • Start date Start date
J

jtagpgmr

I need help coming up with a way to create a c# program to help me
Telnet to a hostIP.. Any suggestions.. or a way to start..
 
You want SOCKETS
System.Net namespace I think.

Telnet (to my understanding) is just a connection.
So if you check out TCP sockets in MSDN you should get all the answers
you need.
 
A *full* implementation of a telnet client (with complete vt100
terminal emulation, for example) is a serious undertaking. However, the
most important part--typing text to the server, and having it send text
back to you--is about a 5-minute programming project for someone
familiar with sockets, and is a reasonably simple "my first sockets
program" sort of project.

In concept it's extremely easy: just connect on TCP port 23 to the
machine you're after, send what you type over the socket, and display
everything you receive on the screen. General-purpose network utilities
like "netcat" can act as a telnet client in a pinch.

System.Net.Sockets has what you're after (the "Socket" class).
Unfortunately, in order to get a satisfactory user experience, you have
to listen for both keyboard and remote network input at the same time,
and the .NET sockets implementation uses a slightly more complicated
system of callbacks instead of events for asynchronous operation.

You've got a few options. The easiest is "polling" -- that is, using a
timer to check at regular intervals to see if data is waiting on the
network. This is very inefficient and leads to a sluggish interface.

You could create two threads, your primary one responds to user
interface events and sends data over the socket when needed. The
secondary one waits for data inbound over the network and displays it
to the screen. Better, but not optimal.

The final and best option is to just suck it up and learn how to
properly do asynchronous (i.e. thread pool based) programming with .NET
using BeginReceive() and EndReceive(), BeginSend() and EndSend(), etc.

Bear in mind that the last two options involve multithreading and lead
to a situation where the thread that receives data off the network is
NOT the thread that controls the user interface. If you're building a
console-based project, this isn't an issue, but windows (forms,
buttons, etc.) are only allowed to have one thread interact with their
UI components, and that thread has to be the primary user interface
thread. What saves you is that Control implements the
ISynchronizeInvoke interface, allowing you to call Invoke() or
BeginInvoke() on any control or form delegate and transfer control to
the correct thread.

But that's all a bit down the road for you. First things first:
Sockets.
 
I need help coming up with a way to create a c# program to help me
Telnet to a hostIP.. Any suggestions.. or a way to start..


Take a look at the System.Net.Sockets.TcpClient class, it should allow you
to do everything you want as long as you dont need terminal emulation.

- Mark
 
Back
Top