• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Socket Programming

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how to detect connection has gone before sending response.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic