ChrisPeterson
ChrisPeterson

Reputation: 419

boost::asio::async_connect creates not only one TCP connection but two

I have just realized looking through TCPView that one single TCP connection established using boost::asio creates two connections. One of them using local ports and a second one with the desired remote port. Why? Is this behaviour normal? Is there a way of creating just one?

This question was originally posted several years ago:

http://boost.2283326.n4.nabble.com/ASIO-tcp-socket-async-connect-connections-count-tc3901601.html#none

but nobody replayed.

Edit:

I'm connecting to the port 8001 and this is what I see with netstat -nao:

TCP    127.0.0.1:10246        127.0.0.1:8001         ESTABLISHED     3252
TCP    127.0.0.1:10244        127.0.0.1:10245        ESTABLISHED     3252
TCP    127.0.0.1:10245        127.0.0.1:10244        ESTABLISHED     3252

Thank you!

Upvotes: 1

Views: 404

Answers (1)

user207421
user207421

Reputation: 310980

This is two connections, not three. Check the port numbers. Evidently the library creates a connection to itself for some reason.

It would be interesting to know whether it happens again when you create a second connection.

Upvotes: 0

Related Questions