0

Is it possible on Windows 7 to write a C++ or .NET program that finds out whether an existing, connected TCP socket created by another program has any data in its send or receive buffer?

Use case: There's a 16-bit legacy application doing TCP communication with some .NET applications. To work around a concurrency issue in the legacy app, it would be helpful if we could inspect either of two sockets that are connected to each other and tell whether there's some data sent on one end but not yet received on the other end. The connection is TCP and the sockets are on the loopback interface (127.0.0.1).

Approach: WSADuplicateSocket() + WSAPoll() could be the solution but I don't know how to get a hold of the socket handle programmatically because the socket is created by another program.

Norman
  • 1,975
  • 1
  • 20
  • 25
  • 1
    `WSADuplicateSocket()` has to be called in the process that created the socket. So even if you could find an open socket handle in another process, you would have to inject code into that process in order to duplicate its socket and send it to your process. It is possible to find an open socket handle in another process, but it is not trivial to implement: [C++ Get Handle of Open Sockets of a Program](http://stackoverflow.com/questions/16262114/) – Remy Lebeau Sep 07 '15 at 19:15
  • Thanks, M. Lebeau! It seems to be the only way. We chose not to implement it, though. – Norman Sep 21 '15 at 14:32

0 Answers0