• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Socket Programming

 
varun kukreja
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


so how normal web server detect the client is closed or not.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not while the request is being processed. At the earliest when the response is meant to be sent but the connection has gone stale.
 
varun kukreja
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how to detect connection has gone before sending response.
 
drac yang
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic