I am using a normal socket with TCP/stream, trying to get the latency.
Send cannot be measured as it returns immediately even if the data was multiple megabytes.

Measuring receive doesn’t work for small packets as it might return all the data at once.
Ping class doesn’t work due to windows firewall on the other side(Disabling it is not a solution).

And internally TCP does know the latency so the information is there just how to get it?
Literally, every program/game has a ping counter so it should be possible somehow.

And internally TCP does know the latency
Does it? I don’t believe the header contains a time stamp.
Literally, every program/game has a ping counter so it should be possible somehow.

Sure. You can easily make a ping-like API.
Yeah. Stamp the inbound message with the time sent from the server.
Ping is simply the time it took for the server to receive a response after it sent the request. So send a message where you keep track of the timestamp and get the current time when you receive the response: receive time – send time = latency.

You will need to use the SIO_TCP_INFO control code on Windows and TCP_INFO on Linux. Look for RTT.

source