How to Create a Chat Server with Netcat

Netcat is a very powerful network utility for Linux. Netcat was developed in 1995 and has many advanced usages. It featured as one of the Top 100 network security tools of 2006 at rank #4.With netcat, we can perform numerous networking tasks like port scanning, managing connections and setting up servers. One very basic usage of netcat is shown here.

Create a chat server/Client:

Netcat can be used to create a chat server and client. With netcat, we can setup a computer as a chat server and another as a chat client which would connect to that server. This enables chatting between two computers on a network.

To create a chat server, enter this into a terminal:

nc l p port_number'

This will set up a tcp server on the host at the port specified as port_number’. This makes netcat listen to the specified port and relays the incoming message on the terminal with stdout. Connect to the chat server using:

nc server_ip' port_number'c

Now, any connection made to the server on the specified port will set up a chat client through the terminal with stdin.

If you are on a Mac, use only the l switch to create a chat server. So, your command should look like:

nc l port_number'

Connecting to the chat server on a Mac is the same as given above.

Published by

Chinmoy Kanjilal

Chinmoy Kanjilal is a FOSS enthusiast and evangelist. He is passionate about Android. Security exploits turn him on and he loves to tinker with computer networks. You can connect with him on Twitter @ckandroid.