I would like to use netcat to listen to data and receive only ONE packet. How does one do this?

  • I don't think you can do that with nc. If you're actually "listening" with nc, it's a stream socket, and message boundaries are not preserved, so you cannot be sure that a single read won't be assembled from multiple packets (or vice-versa). If instead you're using the -u option to bind to a datagram socket, then a) you won't be able to receive any data from clients that use tcp/stream sockets b) each read(2) or recv(2) syscall will return a packet, but good luck convincing any shell utility to do a single read (not up to newline, some delimiter or a fixed length). – mosvy Apr 4 at 8:07
  • Thanks. It is UDP data and I wanted to get one read of the data. socat may be the way to go. – Xofo Apr 4 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.