Java 聊天 - 仅根据请求连接
我刚刚编写了一个 Java 服务器-客户端聊天(具有多个客户端),他们可以在其中登录、聊天和注销。套接字始终启动并且我循环监听。
现在我必须对这种聊天进行编程,其中连接并不总是打开,因此连接只是“根据请求”(当有人发送消息时)加星。
我该怎么做?你能给我一些我应该谷歌搜索的关键词吗?
I just programmed a Java Server-Client Chat (with multiple clients) where they log in, chat and log out. The socket is always started and I listen in a loop.
Now I have to program this kind of chat where the connection isn't always open, so the the connection just stars "on request" (when someone sends a message).
How do I do this? Could you give me some keywords which I should google?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想创建没有打开连接的服务器和客户端(如果我错了,请纠正我),您将必须手动打开和关闭连接。因为这些“连接”代表了网络上的流。
您可以考虑的另一个选项是使用 UDP,但这不会根据请求关闭和打开连接它仅消除了 TCP 的开销及其可靠性功能。
来自 Oracle.com 上的数据报课程:
If you want to create a Server and Client that does not have a Open Connection (Correct me If I am wrong) you will have to Open and close the connection manually. As these "connections" represent Streams across the network.
Another Option you can consider is maybe using UDP, but this does not close and open a connection on request it only removes the overhead of TCP and it's reliability features.
From the Datagram Lesson on Oracle.com: