Send a socket between applications c#

江枫思渺然 提交于 2019-12-02 06:37:35

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.

No need to forwarding the connection, it can be use to act as a middle men

  1. You receive the first connection
  2. Process some rules
  3. All ok, connect to AppB and everything that get's from AppA, send to AppB
  4. If Rules say "no", send an error to AppA
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!