【问题标题】:How to share a socket single connection between two clients?如何在两个客户端之间共享一个套接字单连接?
【发布时间】:2014-02-19 17:16:22
【问题描述】:

我想知道如何在两个客户端之间共享一个套接字单一连接。我已经按照以下方式进行了编程,需要为其余的开发提供建议。

   Socket (Java desktop program)
               |
               |
     |<---------------------->|
     |                        |
    iOS Mobile client      Java Applet (Runs on desktop where same Socket is there)

步骤是,

1. Java Applet connect with this socket and gets a random number from this socket, in the very first call. It is developed. 

[Socket program accepts client and creates a Thread and runs ]

2. I have a text field in iOS Mobile client where user will type that random number (shared the rand number via phone or chat) which it got from that Applet. It is developed.
3. iOS Mobile client sends this random number and also get it connected with socket. It is developed.
4. I need to share images from iOS client to Applet now via this socket established.

我想知道,如何使“Applet 与套接字连接”和“iOS 客户端与套接字”处于同一连接中,以便我可以通过此套接字连接将图像从 iOS 应用程序共享到 Applet?可以像这样在两个客户端(iOS 和 Applet)之间共享单个套接字连接吗?

请告诉我,如何在两个客户端之间建立相同的连接来实现上述第四点。

谢谢!

【问题讨论】:

    标签: java sockets serversocket


    【解决方案1】:

    iOS 客户端和小程序之间没有连接。

    虽然您可以尝试在两者之间建立连接,但最好让您的服务器(Java 桌面程序)充当代理,将从一个套接字上的 iOS 客户端接收到的图像发送到另一个套接字上的小程序。

    【讨论】:

    • OK..所以你是说,我要从iOS和Applet分别连接到Socket?
    • 是的,两者都分别连接到服务器并通过它共享数据,使用随机数计算出要连接的套接字。
    • 好的,知道了!你希望我在请求套接字时发送随机数吗?如果我有多个单独的移动客户端,它会工作吗?
    • 您将连接套接字,发送号码,然后取决于服务器如何解释该号码 - 如果您需要使用单个小程序支持多个 iOS 客户端,那么您必须编写代码那样。
    • OK..它不会是带有单个小程序的多个 iOS 客户端,而是带有多个套接字的多个 iOS 客户端。因此,每个 iOS 客户端都将与单独的 Applet 共享数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 2023-01-17
    • 2023-03-23
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2019-11-19
    相关资源
    最近更新 更多