Simple Network Server Part 1
Created on: 2015-11-06 19:00:00 -0500
Categories: Network Applications
The majority of my work entails developing network centric applications. Often I need to experiment with various technologies to see how they work. One way of testing certain technologies is using a simple server to listen for network connections and display the contents of the packet to the screen. This helps me in understanding what is being sent from the client to the server. Based on my experience there are a few ways to accomplish this. In this quick tutorial I will go over one of 3 methods I use to do this.
The simple server we will be using today simply prints the contents of the packet to the echo server’s console. This example can easily be extended to handle more debugging situations. We will use Fedora 20 as the OS in this tutorial. But Methods 2 & 3 should work on a Windows system.
If you are using any Linux system, there is a command line tool called Netcat (aka ncat or nc). At the same time we will install telnet to do some interactive communication with the server. We will also install the netstat command line tool to help us with this tutorial. To install Netcat and telnet run following command:
Now the Netcat application is now available for you to use. The next step is to determine which IP Transport layer (TCP or UDP) and port number to use. In this example we will first create a server to accept TCP on port 8088. The port has been randomly chosen and no other applications are currently using this port.
If you are unsure what TCP ports are available to use you can run the following command:
You will get a list of active applications listening to certain ports. Under the column ‘Local Address’, is the list of used ports. The convention is usually listening IP address then semicolon then port number.
Lets start the TCP echo server on port 8088 listening on 127.0.0.1 with the following command:
From another console window issue the netstat command again and check if the application is now listening to port 8088.
Now run a telnet session to the server and type in some text.
You will notice that the text you enter will be sent back to you through the telnet window. Now kill the Netcat session (by pressing Ctrl-C in the netcat console).
It should be noted that Telnet uses TCP. If we need to test UDP we can accomplish that with the Netcat application itself. Lets restart the Netcat echo server but with the –udp flag and verify it is running with netstat listing UDP servers.
Now lets send a UDP packet.
If you want to use the echo server one on computer and a client from another you can simply substitute 127.0.0.1 with the IP address of the server. In the case of Fedora 20 and up, you may need to add a firewall rule to allow this. This can be done with the following command:
In my next tutorial I will show how to quickly set up Python to act as an echo server.