What is the simplest way to test a plain socket server

18

6

I have a server which listens on a socket for incoming connections and outputs a welcome text ("Hello world"). What is the simplest way to test this with plain tools from the operating system (here OS X)? I'd imagine something like a good old RS232-terminal application:

mac:~ mike$ terminal 192.168.92.123 1234
Hello world
>

Mike L.

Posted 2010-11-03T19:16:14.327

Reputation: 4 539

This is a port, not a socket. If you actually want to test a socket, you should use nc -U on OS X and on Linux, use socat, e.g. socat - UNIX-CONNECT:/tmp/memcached.sock. – Simon Woodside – 2016-06-09T06:06:50.720

Answers

30

Depends on the kind of tests you want to run? If you want to test establishing a connection and sending some data I can think of two simple tests. Use netcat (nc) to "echo" some data into a remote socket, or use telnet to connect to it interactively.

If your server is listening on foobar.com, port 1234 you could test it like this:

bro@host:~ $ echo "Some data to send" | nc foobar.com 1234

Same address/port as above, but make the session interactive:

bro@host:~ $ telnet foobar.com 1234
Trying foobar.com...
Connected to foobar.com.
Escape character is '^]'.
Type some data to send here

Tim Bielawa

Posted 2010-11-03T19:16:14.327

Reputation: 990

Thanks, I've tried telnet, but it timed out. As I found out, it was a firewall issue. – Mike L. – 2010-11-03T19:56:32.640