jmlaios
jmlaios

Reputation: 129

how to put tcp data from netcat to variables?

I have set up a server with the usual nc - lk <port> command.

My client sends tcp data to the server socket in the form of xxx,yyy which are numbers.

I want every time the client connects that the values of xxx and yyy would be stored in variables in order to use them later.

From what I understood I must work with pipes, but I am not sure how to do this.

Upvotes: 1

Views: 3083

Answers (1)

Alastair McCormack
Alastair McCormack

Reputation: 27704

You have two options:

  1. Pipe the output to a file for later reading
  2. Read each line and do something with it in realtime:

For example:

nc -lk 8889 | while IFS=, read -a p
do echo ${p[1]} ${p[0]}
done

Upvotes: 2

Related Questions