How to logout

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

How to logout

hokada
Please tell me the way to logout. Should I do AtmosphereEvent.resume() in onEvent method?

And the following error happened, when I close my browser after doing suspend().
  java.net.SocketException: Connection reset by peer: socket write error

Should we write try-catch in onMessage method to handle the disconnected connection or are there any way to do it?

[Environment]:
 Atmosphere CPR0.2, Tomcat6.0 on WindowsXP.

Thank you in advance,
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to logout

Jeanfrancois Arcand
Salut,

hokada wrote:
> Please tell me the way to logout. Should I do AtmosphereEvent.resume() in
> onEvent method?

By log out, you means resuming the connection?

>
> And the following error happened, when I close my browser after doing
> suspend().
>   java.net.SocketException: Connection reset by peer: socket write error

Can you post the entire stack trace? I suspect this is from Tomcat
trying to write something on a closed connection.

>
> Should we write try-catch in onMessage method to handle the disconnected
> connection or are there any way to do it?

Probably yes. If you try to write on a invalid connection, the usual
IOException will occurs. But first show me the entire stack trace :-)

A+

-- Jeanfrancois


>
> [Environment]:
>  Atmosphere CPR0.2, Tomcat6.0 on WindowsXP.
>
> Thank you in advance,

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to logout

hokada
Thank you for your replying.

> By log out, you means resuming the connection?

Yes.

Before reproducing this error, the latest atmosphere has been happened the other issue, which was not be able to resume the suspended connection. The client-side code got messages instead of resuming. Here is a source code.

public class TestAtmosphereHandler implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {

        private final Log log = LogFactory.getLog(getClass());

        public AtmosphereEvent<HttpServletRequest, HttpServletResponse> onEvent(AtmosphereEvent<HttpServletRequest, HttpServletResponse> event) throws IOException {
                HttpServletRequest request = event.getRequest();
                HttpServletResponse response = event.getResponse();

                Map<String, Object> data = ..... // get data from request
                int actionId = (Integer)data.get("action-id");
                switch (actionId) {
                case 1: // subscribe
                        event.suspend();
                        log.info("action:Suspended");
                        response.getOutputStream().flush();
                        break;
                case 2: // publish
                        event.getBroadcaster().broadcast(data.get("message"));
                        log.info("action:Broadcast");
                        ..... // write actionId to response  
                        break;
                case 3: // unsubscribe
                        event.resume();
                        log.info("action:Resumed");
                        ..... // write actionId to response  
                        break;
                default:
                }
                return event;
        }

        public AtmosphereEvent<HttpServletRequest, HttpServletResponse> onMessage(AtmosphereEvent<HttpServletRequest, HttpServletResponse> event) throws IOException {
                if (event.isCancelled()) {
                        log.info("Cancelled");
                } else if (event.isResuming() || event.isResumedOnTimeout()) {
                        log.info("Resumed");
                } else {
                        log.info("## Broadcasted Message ## " + event.getMessage());
                        ..... // write event.getMessage().toString() to response
                }
                return event;
        }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to logout

Jeanfrancois Arcand
Salut,

I've finished my JavaOne presentation so I will take a look ASAP at your
issue. Sorry for the delay.

A+

- Jeanfrancois

hokada wrote:

> Thank you for your replying.
>
>> By log out, you means resuming the connection?
>
> Yes.
>
> Before reproducing this error, the latest atmosphere has been happened the
> other issue, which was not be able to resume the suspended connection. The
> client-side code got messages instead of resuming. Here is a source code.
>
> public class TestAtmosphereHandler implements
> AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
>
> private final Log log = LogFactory.getLog(getClass());
>
> public AtmosphereEvent<HttpServletRequest, HttpServletResponse>
> onEvent(AtmosphereEvent<HttpServletRequest, HttpServletResponse> event)
> throws IOException {
> HttpServletRequest request = event.getRequest();
> HttpServletResponse response = event.getResponse();
>
> Map<String, Object> data = ..... // get data from request
> int actionId = (Integer)data.get("action-id");
> switch (actionId) {
> case 1: // subscribe
> event.suspend();
> log.info("action:Suspended");
> response.getOutputStream().flush();
> break;
> case 2: // publish
> event.getBroadcaster().broadcast(data.get("message"));
> log.info("action:Broadcast");
> ..... // write actionId to response  
> break;
> case 3: // unsubscribe
> event.resume();
> log.info("action:Resumed");
> ..... // write actionId to response  
> break;
> default:
> }
> return event;
> }
>
> public AtmosphereEvent<HttpServletRequest, HttpServletResponse>
> onMessage(AtmosphereEvent<HttpServletRequest, HttpServletResponse> event)
> throws IOException {
> if (event.isCancelled()) {
> log.info("Cancelled");
> } else if (event.isResuming() || event.isResumedOnTimeout()) {
> log.info("Resumed");
> } else {
> log.info("## Broadcasted Message ## " + event.getMessage());
> ..... // write event.getMessage().toString() to response
> }
> return event;
> }
> }
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...