Simple Network Server Part 2
Created on: 2015-11-07 19:00:00 -0500
Categories: Network Applications
In my last tutorial I went over how to set up a quick server to help in network centric application development. We went over how to set up Netcat to act as a simple echo server. In this tutorial we will go over how to use Python to set up an echo server. Python makes prototyping development very fast with less than 20 lines of code you can quickly set up an echo server.
In this first example we will setup a UDP based echo server. The code we will use is shown below and is available from my github repo file named udpSimpleServer.py
To run the code from command line simple issue the following command:
In another console window use Netcat to access the server localhost 8088. Enter in a line and press enter to have the server echo back the line.
From the server side you will see the following:
You can kill both processes using Ctrl-C . The next code illustrates how to do the same using TCP as the transport. This file is also available from the github repo as tcpSimpleServer.py.
You can run it by using the following command:
Then telnet to it as shown in the example.
The server side will look like the following.
If you need to change the IP address to access the server from another computer simply change the IP lines in either code and run the server. Remember to add the firewall rules to allow network access to the server.
While this solution is not so elegant it will quickly get you up to speed with testing and troubleshooting your network application. In the future the two applications will be merged into a more elegant application.