我有聊天客户端服务器应用程序,我们正在对其进行扩展。所以我需要在两个聊天服务器之间进行服务器间通信。
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 服务器如何实现此类功能。我相信您只需要编写另一个服务器来将您的服务器作为客户端处理并向它们发出请求以找到具体的用户。
关于java - 通过 Java 套接字进行服务器间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187027/