aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Java Socket Programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Java Socket Programming" Watch "Java Socket Programming" New topic
Author

Java Socket Programming

varun kukreja
Greenhorn

Joined: Apr 17, 2013
Posts: 6

Hi

I am making a server side program using socket programming in java,
which handle multiple requset from the client.
Here client is browser not a client program.
Server accept request from browser and process request using Thread.
in response Web Server sending Continuos data to browser as a streaming
Am getting problem
when user close the broswer or change the tab or minimize the broswer.Then
Server is not able to detect browser states on socket.

why Data is continuosly sending by server program to socket when browser is minimize.
How we can detect browser states on java socket means tab,close or minimize.

i want to know
How apache tomcat detect wheather the browser is open or close or tab change in browser.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

varun kukreja wrote:Here client is browser not a client program.


A browser IS a client program.

when user close the broswer or change the tab or minimize the broswer.Then
Server is not able to detect browser states on socket.

why Data is continuosly sending by server program to socket when browser is minimize.
How we can detect browser states on java socket means tab,close or minimize.


It is impossible for the server to detect anything the client doesn't tell it. If the client doesn't close the socket or the stream that it's reading, or doesn't stop calling read(), then there's no way for the server to know that the client has been minimized. Minimizing a window has nothing to do with reading from a socket, unless that client chooses to explicitly link the two.
varun kukreja
Greenhorn

Joined: Apr 17, 2013
Posts: 6


so how normal web server detect the client is closed or not.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

varun kukreja wrote:

so how normal web server detect the client is closed or not.


They don't. They can only detect that the socket has been closed or the there have been no more attempts to read from it. There's no way they can know anything about the overall state of the client app.
varun kukreja
Greenhorn

Joined: Apr 17, 2013
Posts: 6
if user sends request to tomcat server and mean while user closes the browser then
will server detect closing of browser or not.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
Not while the request is being processed. At the earliest when the response is meant to be sent but the connection has gone stale.


Ping & DNS - my free Android networking tools app
varun kukreja
Greenhorn

Joined: Apr 17, 2013
Posts: 6
So how to detect connection has gone before sending response.
drac yang
Ranch Hand

Joined: Apr 19, 2013
Posts: 61
varun kukreja wrote:So how to detect connection has gone before sending response.

ServerSocket's method accept would throw IOException, if the exception happened, means the connection has gone.


science belief, great bioscience!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Socket Programming