socketsnetwork-programmingboost-asionetcat

Force ncat to send packet without closing connection


I wrote a socket client using ASIO standalone library. To test the client, I downloaded the windows version of ncat utility from https://nmap.org/download.html. The client program sends a packet and wait for an acknowledgment from the server. Upon receiving the ack, client send the next packet.

I'm running the ncat like this

c:\> ncat -l 8801 -v
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::8801
Ncat: Listening on 0.0.0.0:8801
Ncat: Connection from 127.0.0.1.
Ncat: Connection from 127.0.0.1:2177.
sending message-1   # this is the message received from client
ack-1               # I would like to send this msg to client without closing the connection

But I'm unable to send an acknowledgement from ncat program. Pressing enter key doesn't send the current text on the console. Pressing ctrl-c sends the packet but causes the ncat utility to close the connection as well.

Is it possible to send the current text on the console as a tcp packet using ncat?


Solution

  • When reading the man-page it does seem as if line-wise buffering is the default (and also only) option.

    This means you whould expect the line to be sent when you press Enter in the terminal, signaling EOL to the ncat's stdin stream.

    This tells me your client code runs a composed read operation (like async_read) without a suitable completion condition.

    Consider posting your code, or figure it out for yourself using e.g.

    asio::async_read_until(s, buf, "\n", handler);