I'm sorry if this question has already been asked but I haven't found it.
I have a netcat server listening on a local port and redirecting output to file.
nc -l -u -p 11000 > test.json
That's all well and good. The problem is that the 3rd party executable writing to that port is sending packets without any termination characters (e.g., carriage return or line feed). I know this because I've captured the packets in wireshark and inspected them. As a result the messages appear to be stuck in a buffer at some point and never get written.
The only work around I've found is to send spoofed packets from the 3rd party executable containing a line feed. These spoofed packets cause whatever buffer is capturing the messages to clear and redirect output to file at that point.
Here is an example of a spoof command that clears the buffer.
"" | nc -u -s 127.0.0.1 -p 61618 localhost 11000
My assumption is that the buffer exists within nc given that it seems to be source specific (i.e., I have to spoof the source of a packet to get the buffer to clear). The obvious solution would be to append line feeds to the packets I care about but unfortunately I don't have control over the 3rd party executable writing these packets.
Any suggestions? I'd rather not write an entire application to simply capture messages and write them to file. My shell environment is PowerShell so pseudo workarounds such as stdbuf or unbuffer don't work for me (and these wouldn't help anyways if the buffering is occurring in netcat as I suspect).