Skip to main content

UCSPI-TCP package tips

· One min read
Hreniuc Cristian-Alexandru

Install ucspi-tcp:

apt-get install ucspi-tcp

This pacakge contains this list of tools

Create tcp server from bash using tcpserver command from ucspi-tcp:

# content
# read MESSAGE
echo "message: $MESSAGE"
sleep 2
echo " message 2"
sleep 3
echo " message 3"
sleep 2
# ---- end ------- #

# Run tcpserver:
tcpserver -v -H -R IP PORT

# Open a connection:
echo "" | nc IP PORT

This tcp server can open multiple connections in parallel. Verry usefull when you want to have a mock tcpserver.

Fixed issues:

  1. The read command doesn't work if I add it in the script(I had a client written in C++). But it did work when my client was nc....

The fix was to add \n at the end of the string that I was sending from that client. To reproduce this, you can run a client like this: echo -n "sa" | nc IP PORT and the script should contain a read instruction. You will notice that the server will stop at that read instruction.