This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 15961
    
  19

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: 12761
    
    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.
 
Consider Paul's rocket mass heater.
 
subject: Explicit Servlet Response / Servlet response without Servlet Request
 
Similar Threads
URLConnection timeout
What is difference between RequestDispatcher() and sendRedirect()?
Server pushing of a JSP
Chat not Working through Proxy? PLz advice
when to use these methods....