Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > maintain long-lived servlet connection to receive serialized data?

Reply
Thread Tools

maintain long-lived servlet connection to receive serialized data?

 
 
dkso123@comcast.net
Guest
Posts: n/a
 
      04-18-2007
Can anyone help me understand how I might use an HttpServlet to
maintain a socket connection with a client and repeatedly send
serialized data to this client without closing the connection?

The use case is I have a client application (non-browser) interested
in the Servlet's ever-changing data. Rather than poll the servlet for
new data, I'd like the client to establish a long-lived connection to
the Servlet and receive serialized Objects which the client can
deserialize and use. The problems I'm having relate to understanding
how the Servlet could indicate to the client that the data its sending
is complete and ready to be deserialized (i.e., what delimits the end
of an Object stream?) as well as the appropriate use of the servlet
outputstream's flush() and close() methods.

Here's some pseudo-code that hints at what I'm after:

Servlet:
while (true){
ObjectOutputStream objstream = new
ObjectOutputStream(response.getOutputStream());
objstream.writeObject(data);
objstream.flush();
response.getOutputStream().flush();

}

Client:
httpclient.executeGet("someURL");
InputStream response = httpclient.getResponseStream();
ObjectInputStream objInputStream = new ObjectInputStream(response);
while (true){
Object data = objInputStream.readObject();
doSomething(data);

}

Thanks in advance!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maintain DB connection Ken Java 5 10-07-2009 01:33 AM
How to maintain a single network connection? (newbie) Fenster Blick Ruby 2 12-15-2007 03:31 AM
Can't maintain wireless connection. =?Utf-8?B?TjggSA==?= Wireless Networking 2 10-29-2007 03:40 PM
how to use servlet to receive message (not soap message) John Java 8 03-28-2005 01:39 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM



Advertisments