my dog learned polymorphism
The moose likes Sockets and Internet Protocols and the fly likes server response to multi clients Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "server response to multi clients" Watch "server response to multi clients" New topic

server response to multi clients

Itamar Levi

Joined: Oct 27, 2012
Posts: 16

What is the right way to create a server client communication
1. client send a message to server
2. server send back a message to multi client (more then one).

Is it right to to it on the traditional way with JBoss server and HTTP protocol?

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
That depends on what kind of client this is, and what kind of server. For HTTP the model is one client -> one request -> server -> one response -> to the same client; clients are free to send several requests in parallel (or in a row) to the same server, or to send several requests to different servers.

I'm not sure if this helps, but then, I didn't really understand what you were asking by "what is the right way...", or what you mean by "traditional way".
Itamar Levi

Joined: Oct 27, 2012
Posts: 16
Let's say i would like to build a group chat.
if one of the clients is posting a message (client send a http request to the server)
now the server has to send the response/request back but to all other clients (to all group members).

the question is in the server-side how can the server response to some clients by getting only one response from one client.
or maybe using a http protocol or server is not recomended in this application?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

There are two options: One is to have each of the clients poll for responses. That would mean that every second (for example) the client would send a message saying essentially "Got anything for me?" This can readily be done with HTTP as the protocol. It may not be scalable to thousands of clients, but then I can't really envisage a chat involving thousands of people either.

The other is for each of the clients to run a local server waiting for requests, and then the main server would send its "response" to each of the local servers. This conceivably could be done with HTTP as the protocol, but then the clients couldn't run in a browser. They would have to be standalone applications to be able to run an HTTP server. Also, it could only run on a single network, i.e. a LAN.

So if you're just doing this for programming practice, I would go with the first option. And if you're doing it for a real-life project to be used in production, I would go with the option which involved installing software already written by somebody else.
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 517

WebSockets (JSR356 / RFC6455) might be an option as well - it can provide a TCP-based full-duplex between two endpoints (the client-server relationship gets upgraded to peer-peer).

There is support in Java EE 7 for WebSockets, and Wildfly 8 has a working implementation.
I agree. Here's the link:
subject: server response to multi clients
It's not a secret anymore!