Skip to content

Explain how to use nc (netcat) to test both the client and the server #16

@NicMcPhee

Description

@NicMcPhee

We currently talk about things like telnet, which are really ancient. A much better (and more flexible) approach would be to use nc (netcat).

We can use things like

nc 127.0.0.1 60606

to open a connection to the specified IP and port, and then anything we type goes to that service and whatever it returns comes back to us, making it perfect for testing the echo server.

We can also use file redirect to try things like binary files:

nc 127.0.0.1 60606 < test_image.jpg > /tmp/image.jpg

We can even use nc to "fake out" the server:

nc -l 127.0.0.1 60606

The -l says to listen on that specified port, so it's like a server. Anything that comes in is printed in the terminal, and anything we type in will go back to whoever is connected to this port. This can be used to test the client by confirming both that what's typed on the client appears on the server, and what's entered on the server appears on the client.

DigitalOcean has some nice tutorial material on nc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions