R
Richard Maher
Hi,
[Please point me to the correct forum if this isn't it, otherwise please
help if you can.]
Let me start by stating the basic requirement: - In a browser environment, I
wish to connect to a server (other than the html webserver that is hosting
the page) via a TCP/IP socket and exchange messages when and as needs be
but, once established, keep the connection open to the server until the
browser instance is shutdown. Ideally, I think I'm looking for something
that can work with html -> Javascript -> Java Applet. The user must ne free
to jump from page to page and tab to tab while the network connection lives.
Solution 1. Java Applet - Init() and Destroy()
Use the Init() method to create the socket and connect to the server and the
Destroy() method to close the socket. This seemed to be a perfect match to
my requirements! Until someone pointed out to me that almost all (see list
below) browsers call the Destroy() method whenever a new page is displayed
:-( This is *totally* at odds with all documentation I've seen for the
Destroy() method. What is the difference between Stop() and Destroy() if the
latter is called at *every* page change. Is it only 'cos I'm *not* using a
seperate thread for the Applet? Is there a Browser setting that controls
this?
Solution 2. Java Applet - Init() and never close.
If I ignore Destroy() altogether and simply stick a "if not
mysocket.isConnected() then" in the Init() method, and never *explicitly*
close the socket then that should work shouldn't it?
Two questions (at least) immediately spring to mind: -
(a) Will the Socket *ever* get closed (even when the browser is closed) and
the JVM collect the garbage, or will it simply leak resources until the
client runs out of sockets or memory?
(b) If the page and/or Applet is reloaded will the memory containing the
Socket structure be reinitialized and a false negative be returned to
isConnected() even though the other socket is still there?
Public/Private/Static/Session Variables needed?
Solution 3. Frames
Put the Applet in a seperate (possibly invisible) frame that is never
changed and therefore the Destroy() is never called until browser exit?
Solution BEST. *Please* tell me!
Surely this is not rocket science? I simply wish to fire up a page which
loads an applet, connect to the server, and keep that connection up and
ready for action no matter what the user does (short of closing the
browser). I simply cannot be Christopher Columbus here! Please advise how
best to achieve this functionality.
I'm not great with Java or OO code in general but for a complete discussion
of what I'm attempting you can look at the following thread: -
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1071300
Thanks!
Cheers Richard Maher
PS. Please *don't* discuss AJAX or Java Web-Start or your personal favourite
way of doing things. I know enough (barely
to know that my request is
both reasonable and valid; please try to anser *the question*.
List of browsers that call Destroy prematurely: -
Browser Platform Version Comment
Firefox Linux 1.5.0.8 calls destroy when change page
Netscape Linux 7.1 (very old version) calls destroy when change page
Konqueror Linux 3.0.3-13 (very old version) does not call destroy but the
page does not work!
Opera Linux 6.1 (very old version) crash!
Explorer XP 6.0 calls destroy when change page, the page does not work due
an javascript error
Opera XP 8.51 does not work due security
[Please point me to the correct forum if this isn't it, otherwise please
help if you can.]
Let me start by stating the basic requirement: - In a browser environment, I
wish to connect to a server (other than the html webserver that is hosting
the page) via a TCP/IP socket and exchange messages when and as needs be
but, once established, keep the connection open to the server until the
browser instance is shutdown. Ideally, I think I'm looking for something
that can work with html -> Javascript -> Java Applet. The user must ne free
to jump from page to page and tab to tab while the network connection lives.
Solution 1. Java Applet - Init() and Destroy()
Use the Init() method to create the socket and connect to the server and the
Destroy() method to close the socket. This seemed to be a perfect match to
my requirements! Until someone pointed out to me that almost all (see list
below) browsers call the Destroy() method whenever a new page is displayed
:-( This is *totally* at odds with all documentation I've seen for the
Destroy() method. What is the difference between Stop() and Destroy() if the
latter is called at *every* page change. Is it only 'cos I'm *not* using a
seperate thread for the Applet? Is there a Browser setting that controls
this?
Solution 2. Java Applet - Init() and never close.
If I ignore Destroy() altogether and simply stick a "if not
mysocket.isConnected() then" in the Init() method, and never *explicitly*
close the socket then that should work shouldn't it?
Two questions (at least) immediately spring to mind: -
(a) Will the Socket *ever* get closed (even when the browser is closed) and
the JVM collect the garbage, or will it simply leak resources until the
client runs out of sockets or memory?
(b) If the page and/or Applet is reloaded will the memory containing the
Socket structure be reinitialized and a false negative be returned to
isConnected() even though the other socket is still there?
Public/Private/Static/Session Variables needed?
Solution 3. Frames
Put the Applet in a seperate (possibly invisible) frame that is never
changed and therefore the Destroy() is never called until browser exit?
Solution BEST. *Please* tell me!
Surely this is not rocket science? I simply wish to fire up a page which
loads an applet, connect to the server, and keep that connection up and
ready for action no matter what the user does (short of closing the
browser). I simply cannot be Christopher Columbus here! Please advise how
best to achieve this functionality.
I'm not great with Java or OO code in general but for a complete discussion
of what I'm attempting you can look at the following thread: -
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1071300
Thanks!
Cheers Richard Maher
PS. Please *don't* discuss AJAX or Java Web-Start or your personal favourite
way of doing things. I know enough (barely
both reasonable and valid; please try to anser *the question*.
List of browsers that call Destroy prematurely: -
Browser Platform Version Comment
Firefox Linux 1.5.0.8 calls destroy when change page
Netscape Linux 7.1 (very old version) calls destroy when change page
Konqueror Linux 3.0.3-13 (very old version) does not call destroy but the
page does not work!
Opera Linux 6.1 (very old version) crash!
Explorer XP 6.0 calls destroy when change page, the page does not work due
an javascript error
Opera XP 8.51 does not work due security