Re: [jetty-user] websocket problem

Brett Wooldridge <[email protected]> Tue, 27 Nov 2012 19:11:30 +0900
Newsgroups gmane.comp.java.jetty.support
Message-ID <CAPg6oRON8nKzb-WXfjkwz6zTLdRAzBmt8ife2+800Gb-MV-6dQ@mail.gmail.com>
--e89a8f3ba01b182d8004cf7746a8
Content-Type: text/plain; charset=ISO-8859-1

Yin,

As far as I know, the only way to know there was a disconnection is when
you attempt to write data to that websocket.  When a connection is
physically unplugged, TCP does not actually disconnect the socket, because
such an interruption may be transient.  In jetty, if you have a class that
implements WebSocket.OnTextMessage, for example, you can implement
something (roughly) like this:

pubic void sendMessage(String message) {
   try {
      connection.sendMessage(message); // send message to user's websocket
connection
   } catch (IOException io) {
      connection.close();
   }
}

@Override
public void onOpen(Connection connection) {
   this.connection = connection;
   // join chat room
}

@Override
public void onClose(int closeCode, String message) {
   if (connection != null) {
      connection = null;
      // leave chatroom
   }
}



On Tue, Nov 27, 2012 at 6:40 PM, <[email protected]> wrote:

>  hi all:
>
> I am using jetty-hightide-8.0.4.v20111024, the use of websocket to make a
> chat, I encountered a problem, when three people at the same time online
> chat, when suddenly a man unplug cable out of chat, server is unable to
> determine the connection is disconnected, how the server know unplugged
> network line of human connection state? Can you help me? Thank you very
> much!
>
>
>
>       Best Regards,
>
>  Yin zhang
>
>
>
>
> **********************************************************************************************************************************************
>
> This e-mail is confidential for WistronITS corp. It may be legally
> privileged. If you are not the Addressee you may not copy,
>
> forward, disclose or use any part of it. If you have received this message
> in error, please delete it and all copies from your
>
>  system and notify the sender immediately by return e-mail.Internet
> communications cannot be guaranteed to be timely,
>
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
>
> ***********************************************************************************************************************************************
>

--e89a8f3ba01b182d8004cf7746a8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Yin,<div><br></div><div>As far as I know, the only way to know there was a =
disconnection is when you attempt to write data to that websocket. =A0When =
a connection is physically unplugged, TCP does not actually disconnect the =
socket, because such an interruption may be transient. =A0In jetty, if you =
have a class that implements WebSocket.OnTextMessage, for example, you can =
implement something (roughly) like this:</div>
<div><br></div><div>pubic void sendMessage(String message) {<br></div><div>=
=A0 =A0try {</div><div>=A0 =A0 =A0 connection.sendMessage(message); // send=
 message to user&#39;s websocket connection</div><div>=A0 =A0} catch (IOExc=
eption io) {</div>
<div>=A0 =A0 =A0 connection.close();</div><div>=A0 =A0}</div><div>}</div><d=
iv><br></div><div>@Override</div><div>public void onOpen(Connection connect=
ion) {</div><div>=A0 =A0this.connection =3D connection;</div><div>=A0 =A0//=
 join chat room</div>
<div>}</div><div><br></div><div>@Override</div><div>public void onClose(int=
 closeCode, String message) {</div><div>=A0 =A0if (connection !=3D null) {<=
/div><div>=A0 =A0 =A0 connection =3D null;</div><div>=A0 =A0 =A0 // leave c=
hatroom</div><div>
=A0 =A0}</div><div>}</div><div><br></div><div class=3D"gmail_extra"><br><br=
><div class=3D"gmail_quote">On Tue, Nov 27, 2012 at 6:40 PM,  <span dir=3D"=
ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">YinZh=
[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">




<div lang=3D"ZH-CN" link=3D"blue" vlink=3D"purple">
<div>
<p><span lang=3D"EN-US">hi all:</span></p>
<p><span lang=3D"EN-US">I am using jetty-hightide-8.0.4.v20111024, the use =
of websocket to make a chat, I encountered a problem, when three people at =
the same time online chat, when suddenly a man unplug cable out of chat, se=
rver is unable
 to determine the connection is disconnected, how the server know unplugged=
 network line of human connection state? Can you help me? Thank you very mu=
ch!</span></p>
<p><span lang=3D"EN-US">=A0</span></p>
<p><span lang=3D"EN-US">=A0=A0=A0=A0=A0 Best Regards,</span></p>
<p><span lang=3D"EN-US">=A0Yin zhang</span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-US">=A0</span></p>
</div>
<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;\0065b0\007d30\00660e\009ad4&quot;,&quot;serif&quot;">*********=
***************************************************************************=
**********************************************************</span></p>

<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;Verdana&quot;,&quot;sans-serif&quot;">This e-mail is confidenti=
al for WistronITS corp. It may be legally privileged. If you are not the Ad=
dressee you may not copy,
</span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;Verdana&quot;,&quot;sans-serif&quot;">forward, disclose or use =
any part of it. If you have received this message in error, please delete i=
t and all copies from your</span></p>

<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;Verdana&quot;,&quot;sans-serif&quot;">=A0system and notify the =
sender immediately by return e-mail.Internet communications cannot be guara=
nteed to be timely,
</span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;Verdana&quot;,&quot;sans-serif&quot;">secure, error or virus-fr=
ee. The sender does not accept liability for any errors or omissions.</span=
></p>

<p class=3D"MsoNormal"><span lang=3D"EN-US" style=3D"font-size:8.0pt;font-f=
amily:&quot;\0065b0\007d30\00660e\009ad4&quot;,&quot;serif&quot;">*********=
***************************************************************************=
***********************************************************</span></p>

</div>

</blockquote></div><br></div>

--e89a8f3ba01b182d8004cf7746a8--