Send a socket between applications c#

后端 未结 2 857
一整个雨季
一整个雨季 2021-01-24 13:30

I would like to know if there is a way where you have a .net app name appA where it receives a tcp socket connection and then according to some rules will send the socket connec

2条回答
  •  迷失自我
    2021-01-24 14:13

    Proxy

    One option is to make AppA a proxy. That is, it accepts the connections, and connects on behalf the client to AppB - and merely forwards the data.

    Socket Duplication

    The solution you are really looking for is Socket.DuplicateAndClose() (make sure you read the documentation carefully). This allows you transfer the control of a socket between processes.

    Typically you would:

    • Start AppA, AppB and AppC.
    • Use remoting to allow AppA to communicate with AppB and AppC.
    • When a connection is made to AppA, determine who to send it to and:
      • Duplicate and close the socket in AppA.
      • Send the socket to the child process via remoting.
      • Open the socket in AppB using the Socket(SocketInformation) constructor.

提交回复
热议问题