Search in sources :

Example 6 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class ClientHead method schedulePingTimeout.

public void schedulePingTimeout() {
    SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
    disconnectScheduler.schedule(key, new Runnable() {

        @Override
        public void run() {
            ClientHead client = clientsBox.get(sessionId);
            if (client != null) {
                client.onChannelDisconnect();
                log.debug("{} removed due to ping timeout", sessionId);
            }
        }
    }, configuration.getPingTimeout() + configuration.getPingInterval(), TimeUnit.MILLISECONDS);
}
Also used : SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 7 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class AuthorizeHandler method channelActive.

@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
    disconnectScheduler.schedule(key, new Runnable() {

        @Override
        public void run() {
            ctx.channel().close();
            log.debug("Client with ip {} opened channel but doesn't send any data! Channel closed!", ctx.channel().remoteAddress());
        }
    }, configuration.getFirstDataTimeout(), TimeUnit.MILLISECONDS);
    super.channelActive(ctx);
}
Also used : SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 8 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class WebSocketTransport method connectClient.

private void connectClient(final Channel channel, final UUID sessionId) {
    ClientHead client = clientsBox.get(sessionId);
    if (client == null) {
        log.warn("Unauthorized client with sessionId: {} with ip: {}. Channel closed!", sessionId, channel.remoteAddress());
        channel.close();
        return;
    }
    client.bindChannel(channel, Transport.WEBSOCKET);
    authorizeHandler.connect(client);
    if (client.getCurrentTransport() == Transport.POLLING) {
        SchedulerKey key = new SchedulerKey(SchedulerKey.Type.UPGRADE_TIMEOUT, sessionId);
        scheduler.schedule(key, new Runnable() {

            @Override
            public void run() {
                ClientHead clientHead = clientsBox.get(sessionId);
                if (clientHead != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("client did not complete upgrade - closing transport");
                    }
                    clientHead.onChannelDisconnect();
                }
            }
        }, configuration.getUpgradeTimeout(), TimeUnit.MILLISECONDS);
    }
    log.debug("сlient {} handshake completed", sessionId);
}
Also used : ClientHead(com.corundumstudio.socketio.handler.ClientHead) SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Aggregations

SchedulerKey (com.corundumstudio.socketio.scheduler.SchedulerKey)8 AckCallback (com.corundumstudio.socketio.AckCallback)1 MultiTypeAckCallback (com.corundumstudio.socketio.MultiTypeAckCallback)1 ClientHead (com.corundumstudio.socketio.handler.ClientHead)1 Channel (io.netty.channel.Channel)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1