0

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).

Daniel
  • 23,129
  • 12
  • 109
  • 154
Jan Tacci
  • 3,131
  • 16
  • 63
  • 83

1 Answers1

0

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

Community
  • 1
  • 1
gby
  • 14,900
  • 40
  • 57
  • Thank you very much for the answer!! There is one problem that prevents me from doing what you suggest. The client application is already coded and it's not mine and I don't have access to the source, etc. Therefore I cannot control whether the client app creates a domain socket nor can I have it pass the copy to my own app. :( – Jan Tacci Aug 09 '12 at 16:47
  • This other program that I spoke about requires that you select the process (eg. client.exe) in order for it to work. Could this program be "snooping" around the client to find the socket connection then hijacking it? – Jan Tacci Aug 09 '12 at 16:50
  • You can hijack the socket system call in the client application using LD_PRELOAD. See http://stackoverflow.com/questions/273220/help-with-using-ld-preload for details – gby Aug 12 '12 at 07:51