简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM