Testing TCP / UDP clients and servers with a Linux platform

Sometimes you need a quick method or mechanism to test either a TCP or UDP client or server works, this can be done with the Linux netcat application. Some examples of this application usage are :-

Show Plain Text
Text code
  1. netcat -ul -p3500

This will listen for UDP packets on port 3500 of the Linux machine i.e. server.

Show Plain Text
Text code
  1. netcat -u localhost 3500

This will act as a UDP client on port 3500. On both the client and server you can type text messages and hit to transmit the text to the server or client. The +C combination will allow you to quit either the server or client.

Show Plain Text
Text code
  1. netcat -l -p 3500

This will listen for TCP packets on port 3500 as a server process.

Show Plain Text
Text code
  1. netcat localhost 3500

This will act as a TCP client on port 3500. You could also use the telnet command.

Its also quite useful to figure out what processes are on your TCP or UDP ports. The netstat application is great for this.

Show Plain Text
Text code
  1. netstat -ntpl

This will list all of your TCP ports that are open.

Show Plain Text
Text code
  1. netstat -nupl

This will list all of your UDP ports that are open.

To send a test UDP packet to a server you can use :-

Show Plain Text
Text code
  1. echo -n "foo" | nc -u -w1 localhost 3500
Filed under: Linux  Tags: Debian, Ubuntu

0 Responses to “Testing TCP / UDP clients and servers with a Linux platform”

Sorry, comments have been closed for this post.