Using A Third Party Application To Send Data To An Already Open TCP Connection?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 03:45:23

问题


I am running a client program that communicates with a server using TCP sockets. When I start the client it immediately creates a socket connection with the server and does not close the connection.

What I am wondering is, can I create another application (independent of the client/server apps) that sends data on this already open socket?

I know of a program that seems to do exactly this. The program is designed to sniff packets between the client and server and also allow you to send data on the connection. Before data can be sent you must provide the program with the client process name (eg. client.exe). I believe what it's doing is using the client process as a sort of proxy to the server (which is not what I want to do, I want to be able to connect directly to the server).


回答1:


Yes, you can, udner specific circumstances - provided your 2nd app runs on the same host as the client and that is a Unix OS.

What you need to do is have your client application and 2nd app open a Unix domain socket between them and then get the client application to pass to the 2nd application a copy of the open file descriptor it has obtained for the socket.

See this SO question foe details on how to do that: Portable way to pass file descriptor between different processes



来源:https://stackoverflow.com/questions/11876083/using-a-third-party-application-to-send-data-to-an-already-open-tcp-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!