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 how do I know when client closes the browser ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how do I know when client closes the browser ?" Watch "how do I know when client closes the browser ?" New topic
Author

how do I know when client closes the browser ?

Venkat Ammisetty
Ranch Hand

Joined: Nov 25, 2000
Posts: 42

Hi All
I am devloping the chat application.I have some problems with client logouts.I have used applet on client side and servlets on serverside.For actual communication UrlConnection class is used.
Each client calls the chatservlet ,if he did not have any messages that request will be kept in wait state.suppose when the client closes the browser,In the server side that request should be unblocked.
so how can i know in serverside that client closes the browser, so that i can notify other clients that so and so client logged out from chat application.

thank's

Venkat Ammisetty
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
I'm not sure if you can detect if an applet was closed on the server end however, I do believe that a SocketException is thrown on the server side. If you could just log the IP that created the exception and link it with the user, then you could probably find out. Either that or set a time out if they don't notify the server in x amount of seconds that they're still active. Not sure if you'd want that though.


Rehan Malik
Venkat Ammisetty
Ranch Hand

Joined: Nov 25, 2000
Posts: 42
hai malik
With sockets it can be done,
but for my chat application Iam using URLConnection Object(The reason Iam using URLConnection object to work my chat application under firewall).But using this URLConnection object Iam calling the chat servelet which transferss the messages to the other clients who are in wating state.
In the chat servet I would like to know that which client logsout.
wating for u reply
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hi Venkat,
I think you can use Session Tracking Mechanism for your problem. When a user logs in create a session object and store it whereever you store user info. Now from each request we can trace the user session and do the needful.
Hope you got some idea from this.
Cheers
Binu


Sarath Mohan
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15958
    
  19

Considering the lamentable frequency with which browsers routinely die (or with Winodows, the entire OS), I fear you're never going to achieve complete happiness. However, when an applet is terminated, its stop() method is invoked - you could send a "Logging out" message from there.
Realize, however, that a browser is NOT a "telnet" session - users can flip back and forth between chat pages, open unrelated pages, open multiple chat pages, and do similar wierd things. http is stateless, so any sort of session you maintain is by convention, not enforced or supported by either browser or server. Or, in other words, you can try to manage things by adding the above to your client, but if the server is tracking users, it will require a timeout mechanism to catch the unannounced disconnects.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jason Kilgrow
Ranch Hand

Joined: May 21, 2001
Posts: 47
Ok. I'm going to throw in my 2 cents worth (yeah. i know. not much is it...).
Even though I have not done this, I have read about it and I've wanted to try it out. But, supposedly, with RMI, you should be able to register an event with a listener bean on the server so that when the client bean logs out or the bean, otherwise, dies, it broadcasts an event that the server (listener) bean receives and knows to do...whatever...clean up, etc. And now we're beginning to get to the fringes of EJB's.
Originally posted by Venkat Ammisetty:

Hi All
I am devloping the chat application.I have some problems with client logouts.I have used applet on client side and servlets on serverside.For actual communication UrlConnection class is used.
Each client calls the chatservlet ,if he did not have any messages that request will be kept in wait state.suppose when the client closes the browser,In the server side that request should be unblocked.
so how can i know in serverside that client closes the browser, so that i can notify other clients that so and so client logged out from chat application.

thank's

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how do I know when client closes the browser ?
 
Similar Threads
Chat Application
cleint disconnecting without logging out....
xml and chat.
activate server by client in socket program?
Chat Web Service Using Axis