将聊天服务器实现为WebService [英] Implementing a chat server as a WebService
问题描述
我有一个学校项目,我必须实现一个聊天应用程序,其服务器将是一个java Web服务。
I have a school project in which I have to implement a chat application, whose server will be a java web service.
问题是我一直都是将Web服务视为一种调用远程功能的方式,我不知道如何在Web服务上保持会话活动,也不知道如何跟踪当前聊天,房间等所有人。
The problem is that I've always thought of a web service as a way of calling remote functions, and I have no idea how to keep a "session" active on the web service, nor how to keep track of all the people currently in chat, rooms etc.
推荐答案
据我所知,聊天服务器应该在初始连接后知道其客户端,并将每个客户端消息发送给所有客户端客户端。这肯定需要某种会话维护。我认为正确的方法如下:
To the best of my knowledge, a chat server is supposed to know its clients after an initial connection, and send every client message to all clients. This definitely calls for some sort of session maintenance. I think the right way to do this is as follows:
- 客户端调用Web服务'握手'并提供一些最小的识别细节。
- 服务器返回包含唯一客户端标识符的确认。
- 客户端调用Web服务消息并发送新消息及其标识符。
- 服务器通过标识符识别客户端,将消息分发给所有客户端。
- Client calls web service 'handshake' and provides some minimal identification details.
- Server returns an acknowledgment that includes a unique client identifier.
- Client calls web service 'message' and sends a new message, together with its identifier.
- Server identifies client by the identifier, distributes message to all clients.
我不是确实消息分发应该如何工作,因为Web服务本质上是一种拉服务而不是推送。也许客户端应该为服务器公开自己的Web服务。
I'm not really sure how the message distribution should work, as web services are essentially a pull-service and not push. Perhaps the client should expose its own web service for the server to call.
希望这会有所帮助,
Yuval = 8 - )
Yuval =8-)
这篇关于将聊天服务器实现为WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!