macostcpterminalnetcat

Starting a TCP server from terminal


How do I start a TCP server from the terminal on port 13370 using nc? I was following a tutorial that required starting up a TCP server on 13370 and send requests through it. The tut advised me to open the TCP server using "nc" How do I go on achieving this?


Solution

  • From nc documentation:

    It is quite simple to build a very basic client/server model using nc. On one console, start nc lis-tening listening on a specific port for a connection

    You should use -l parameter, for listening on port 13370:

    $ nc -l 13370
    

    Now you have a tcp server on 127.0.0.1:13370

    On a second console you could connect to your server by using:

    $ nc 127.0.0.1 13370
    

    Please refer also to the documentation link.