java - 通过 Java 套接字进行服务器间通信

标签 java sockets

我有聊天客户端服务器应用程序,我们正在对其进行扩展。所以我需要在两个聊天服务器之间进行服务器间通信。

Problem is: Suppose there are two servers A and B. now Suppose client C1 is TCP Connected with Server A and Client c2 is TCP connected with Server B. Then problem is: as a same appication client C1 and c2 should be able to identifty each other as logged in and available online, but that is not happening becase there is no inter server communication.

Possible solution no 1 is : Log in server A and Server B into each other using TCP connection. Here i can forward the login XML message(String) and DataInputStream to other server through the TCP connection. so every login is transfered to the other server so that every client is accessible to each server and Client C1 can see Client C2 as logged in(online) and vice versa.

Problem with Solution 1 is: Suppose now client C1 can see Client C2 as available online and Client C1 sends message to Client C2. what will happen is Server A Will try to write to DatainputStream for the client C2 which is established on Server B and not on Server A. here is the problem the code will break here and Server A will not be able to send messages to Client C2.

如有任何意见,我们将不胜感激。

谢谢

最佳答案

您可以看看 IRC 服务器如何实现此类功能。我相信您只需要编写另一个服务器来将您的服务器作为客户端处理并向它们发出请求以找到具体的用户。

https://www.rfc-editor.org/rfc/rfc2810

关于java - 通过 Java 套接字进行服务器间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187027/

相关文章:

python - Socket.IO 与 Twisted

java - FTPClient - Java,上传文件

具有太多 Web 服务的 Java EE 应用程序

java - 如何在没有堆栈跟踪的情况下创建/抛出异常?

PHPCrawl 无法创建 SSL 套接字

c# - C# (.net) 下带有 HTTP 服务器的 Keep-Alive 套接字如何发送多个查询?

java - 希尔伯特按分治算法排序?

java - 有没有办法使用 Java 从对象本身内部销毁对象?

sockets - 我可以使UDP b套接字仅容纳一条消息吗?

mysql - 通过 MySQL 套接字与 Zend Framework 连接