websocket problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

websocket problem

YinZhang

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.

***********************************************************************************************************************************************

Reply | Threaded
Open this post in threaded view
|

Re: websocket problem

Brett Wooldridge
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, <[hidden email]> 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.

***********************************************************************************************************************************************


Reply | Threaded
Open this post in threaded view
|

答复: [jetty-user] websocket problem

YinZhang

hi Brett

 

But now the problem is, unplug cable connection, and do not have access to the onclose ( ) method, this is a service deployment in centos6. 2, the jetty cannot determine whether the connection is broken?.

 

If the service is deployed in the window xp system, unplug cable connection into the onclose ( ) method.

 

 

发件人: Brett Wooldridge [mailto:[hidden email]]
发送时间: 20121127 18:12
收件人: [hidden email]
主题: Re: [jetty-user] websocket problem

 

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, <[hidden email]> 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.

***********************************************************************************************************************************************

 

**********************************************************************************************************************************************

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.

***********************************************************************************************************************************************

Reply | Threaded
Open this post in threaded view
|

Re: 答复: [jetty-user] websocket problem

Joakim Erdfelt-9
YinZhang,

Java cannot determine if a connection has an issue that results in it being closed.
(Some examples:  Remote side turned off their power. A physical layer connection has been severed. A cable has been unplugged.  A mobile client has moved to an area with no coverage.  The server had a network interface failure.  A router suddenly stops sending packets to either end.)

Java can only tell if there is a failure when attempting to read or write to that connection.  (Commonly in the form of an IOException, TimeoutException, or SocketException)
If you do not read or write, then as far as Java is concerned, there is nothing wrong.

Now, as far as connections under Jetty, we also have a Idle Timeout mechanism, where if the connection hasn't had any activity within a configured amount of time, the connection is torn down and closed forcefully by Jetty.

--
Joakim Erdfelt <[hidden email]>
Developer advice, services and support
from the Jetty & CometD experts



On Tue, Nov 27, 2012 at 3:25 AM, <[hidden email]> wrote:

hi Brett

 

But now the problem is, unplug cable connection, and do not have access to the onclose ( ) method, this is a service deployment in centos6. 2, the jetty cannot determine whether the connection is broken?.

 

If the service is deployed in the window xp system, unplug cable connection into the onclose ( ) method.

 

 

发件人: Brett Wooldridge [mailto:[hidden email]]
发送时间: 20121127 18:12
收件人: [hidden email]
主题: Re: [jetty-user] websocket problem

 

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, <[hidden email]> 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.

***********************************************************************************************************************************************

 

**********************************************************************************************************************************************

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.

***********************************************************************************************************************************************