Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explicit Servlet Response / Servlet response without Servlet Request

 
NitinN Keswani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
NitinN Keswani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider a Java Message Service approach - the "publish/subscribe" applies to chat.

Bill
 
Hikari Shidou
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic