简体   繁体   English

如何使用Telnet测试我的套接字程序?

[英]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 ? 一切都在标题中,我在Linux上,我有一个C语言的套接字客户端和一个Socker服务器程序,我想用Telnet测试我的服务器,但我似乎找不到方法,你有什么主意吗? ?

Thanks in advance 提前致谢

Let's say your server is accepting incoming TCP connections on port 9999. 假设您的服务器正在端口9999上接受传入的TCP连接。

You can then open up a shell window (on the same machine your server is running on) and enter: 然后,您可以打开一个shell窗口(在运行服务器的同一台计算机上)并输入:

telnet localhost 9999

... and (if all is working as expected), telnet will connect to your server. ...并且(如果所有功能都按预期工作),则telnet将连接到您的服务器。 (if telnet errors out instead with "connection refused", that means no server is accepting TCP connections on that port) (如果出现telnet错误,而是显示“ connection拒绝”,则表示没有服务器在该端口上接受TCP连接)

You can then type ASCII characters into the telnet window, and when you press return, those ASCII characters will be sent to your server; 然后,您可以在telnet窗口中键入ASCII字符,然后按回车键,这些ASCII字符将被发送到您的服务器。 and any output the server writes to its end of the socket will show up in your telnet window. 服务器写入套接字末尾的所有输出都将显示在telnet窗口中。

The caveat is that telnet only works well as a test mechanism if your server is expecting to send/receive ASCII data; 需要注意的是,如果您的服务器希望发送/接收ASCII数据,则telnet仅可以作为一种测试机制很好地工作。 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. 如果OTOH,您的服务器正在发送二进制数据,那么它将在telnet窗口中显示为看起来很奇怪的垃圾字符,而且没有简单的方法将任意二进制数据输入到telnet窗口中以将其发送到服务器。

Some minimal Linux Server doesn't install telnet. 某些最小的Linux Server不安装telnet。

In Redhat / Centos you can do 在Redhat / Centos中,您可以做

yum install telnet

In Ubuntu you can do 在Ubuntu中,您可以执行

apt-get install telnet 

After that you can do telnet 9999. 之后,您可以执行telnet 9999。

Another tools you may want to look at is call "nc", which allow you to communicate via UDP port. 您可能要查看的另一个工具是“ nc”,它允许您通过UDP端口进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM