MisterPur
MisterPur

Reputation: 27

How to use Telnet to test my socket program?

Everything is in the title, i'm on linux, I have a socket client and a socker server program in C and I'd like to test my server with Telnet but I can't seem to find how, do you have any idea ?

Thanks in advance

Upvotes: 0

Views: 12589

Answers (2)

Soya Bean
Soya Bean

Reputation: 107

Some minimal Linux Server doesn't install telnet.

In Redhat / Centos you can do

yum install telnet

In Ubuntu you can do

apt-get install telnet 

After that you can do telnet 9999.

Another tools you may want to look at is call "nc", which allow you to communicate via UDP port.

Upvotes: 1

Jeremy Friesner
Jeremy Friesner

Reputation: 73304

Let's say your server is accepting incoming TCP connections on port 9999.

You can then open up a shell window (on the same machine your server is running on) and enter:

telnet localhost 9999

... and (if all is working as expected), telnet will connect to your server. (if telnet errors out instead with "connection refused", that means no server is accepting TCP connections on that port)

You can then type ASCII characters into the telnet window, and when you press return, those ASCII characters will be sent to your server; and any output the server writes to its end of the socket will show up in your telnet window.

The caveat is that telnet only works well as a test mechanism if your server is expecting to send/receive ASCII data; if OTOH your server is sending binary data, that will appear in the telnet window as strange-looking garbage characters, and also there's no easy way to enter arbitrary binary data into a telnet window to send it to your server.

Upvotes: 3

Related Questions