I have a windows services that bind to some TCP port, this port is use for IPC between my application.
Is there a programming (WinAPI/WinSocket and etc) way to know which application connected to my port?
i.e. in my Windows Services I would like to get a PID of the process that connected to my port.
If you’re looking for WinAPI way of doing the same as
netstat. You probably want the following API:GetExtendedTcpTableLook for the results with
TCP_TABLE_OWNER_PID_ALLargument.The resulting
MIB_TCPTABLE_OWNER_PIDstructure has manyMIB_TCPROW_OWNER_PIDstructures that hasdwOwningPidwhich is the process ID you are looking for.