File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Explicit Servlet Response / Servlet response without Servlet Request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Explicit Servlet Response / Servlet response without Servlet Request" Watch "Explicit Servlet Response / Servlet response without Servlet Request" New topic
Author

Explicit Servlet Response / Servlet response without Servlet Request

NitinN Keswani
Greenhorn

Joined: Jan 17, 2013
Posts: 2
Hi everybody
I have a multiple client and servlet as a server
A client sends a message to server and that message should be delivered to another client

is it possible to send a servlet response without request.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

No it is not. That is a fundamental constraint of HTTP protocol, and it doesn't matter what HTTP server you use, what framework, or even what programming language. HTTP is strictly one request/one response.

A server can make an HTTP request of its own to another server, but it cannot direct a response to anywhere but the place that the request came from, and it cannot generate unsolicited responses. You'd have to use some other protocol than HTTP.


Customer surveys are for companies who didn't pay proper attention to begin with.
NitinN Keswani
Greenhorn

Joined: Jan 17, 2013
Posts: 2
Tim Holloway wrote:No it is not. That is a fundamental constraint of HTTP protocol, and it doesn't matter what HTTP server you use, what framework, or even what programming language. HTTP is strictly one request/one response.

A server can make an HTTP request of its own to another server, but it cannot direct a response to anywhere but the place that the request came from, and it cannot generate unsolicited responses. You'd have to use some other protocol than HTTP.


Hello Tim,
I want to make a online chat application, that is where I am stuck.
can you suggest me some alternative.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Consider a Java Message Service approach - the "publish/subscribe" applies to chat.

Bill
Hikari Shidou
Ranch Hand

Joined: Jan 22, 2013
Posts: 88
Well, in principle, the "client" would need to be a server, so that you can send some message to it without being solicitated by it.

If what you want is a chat, that has been solved long time ago, and there's a pattern for it from even longer before.

All clients must keep calling the server from time to time, like every 1s. That's done easily with AJAX, and has been done way before AJAX was imagined.

Each client will be identified by server. If it has sent a text, server will store it in some queue to serve other clients. If it wanna know if there are new texts, server will send response with all texts added since it last asked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Explicit Servlet Response / Servlet response without Servlet Request