在应用程序之间发送套接字c#

发布于 2024-12-03 20:46:45 字数 123 浏览 4 评论 0原文

我想知道是否有一种方法,您有一个 .net 应用程序名称 appA,它接收 tcp 套接字连接,然后根据某些规则将套接字连接发送到另一个 .net 应用程序名为 appB。 我知道这违反了很多安全和良好实践,但如果可能的话会很有趣。

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 connection to another
.net app named appB.
I know this violates alot of security and good practice,but would be interesting if it would be possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぺ禁宫浮华殁 2024-12-10 20:46:45

代理

一种选择是让 AppA 成为代理。也就是说,它接受连接,并代表客户端连接到 AppB - 并且仅转发数据。

套接字复制

您真正寻找的解决方案是Socket.DuplicateAndClose() (请确保仔细阅读文档)。这允许您在进程之间转移套接字的控制权。

通常您会:

  • 启动 AppA、AppB 和 AppC。
  • 使用远程处理允许 AppA 与 AppB 和 AppC 进行通信。
  • 与 AppA 建立连接后,确定将其发送给谁并:
    • 复制并关闭 AppA 中的套接字。
    • 通过远程处理将套接字发送到子进程。
    • 使用 Socket(SocketInformation) 构造函数在 AppB 中打开套接字。

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.
那支青花 2024-12-10 20:46:45

无需转发连接,它可以用作中间人

  1. 您收到第一个连接
  2. 处理一些规则
  3. 一切正常,连接到 AppB 并将从 AppA 获取的所有内容发送到 AppB
  4. 如果有规则说“不”,向 AppA 发送错误

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文