简体   繁体   English

Java简单RMI聊天应用程序

[英]Java Simple RMI Chat Application

I am trying to make a very simple chat program using RMI ( no GUI's ) but i am struggling for ideas. 我正在尝试使用RMI无GUI )制作一个非常简单的聊天程序,但我一直在努力寻求想法。 How do i register clients when they connect to the server? 客户端连接到服务器时如何注册客户端? When i use 当我使用

RemoteServer.getClientHost() RemoteServer.getClientHost的()

all this does is show the ip address (and they are the same for all clients that connect from the same computer (from multiple command windows). What i am trying to implement is this: when a client logs on he is shown a switch-case menu and ift they press 这一切都是显示ip地址(对于从同一台计算机连接(从多个命令窗口)连接的所有客户端,它们都是相同的。我尝试实现的是:当客户端登录时,他会显示一个开关-案例菜单和他们按下的ift

  1. they get a list of connected clients. 他们获得连接的客户端列表。

  2. sendMessage(client, String) sendMessage(客户端,字符串)

But i do not know how to identify individual clients? 但是我不知道如何识别个人客户?

And when i do, how do i show a string only on that client's window ? 当我这样做时,如何仅在该客户的窗口上显示字符串?

Thanks, 谢谢,

Research: (i have looked at ideas on the web but a lot of them are more advanced than i want. This is a simple application and i do not want to complicate it / copy code i dont understand). 研究:(我已经看过网上的想法,但是很多想法都比我想要的要先进。这是一个简单的应用程序,我不想使其复杂化/复制我不理解的代码)。 There are previous questions on SO but with 0/1 answers (not very popular topic!) or not helpful! 有关于SO的先前问题,但答案为0/1(不是很受欢迎的主题!)或没有帮助!

Looks like i found what i was looking for: 看起来我找到了我想要的东西:

RMI Callback RMI回调

Basically making every client a server, so the server can respond as well as receive messages. 基本上使每个客户端都是服务器,因此服务器可以响应并接收消息。

I have been directed to a resource that might help: 我被定向到可能有帮助的资源:

Java Network Programming and Distributed Computing by David Reilly & Michael Reilly David Reilly和Michael Reilly撰写的Java网络编程和分布式计算

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM