diff --git a/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java b/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java index ec7b747..908575f 100644 --- a/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java +++ b/src/main/java/com/corundumstudio/socketio/handler/AuthorizeHandler.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -85,8 +86,24 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di this.clientsBox = clientsBox; } + @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 {} opens channel but not sended any data! Channel closed!", ctx.channel().remoteAddress()); + } + }, configuration.getPingTimeout() + configuration.getPingInterval(), TimeUnit.MILLISECONDS); + super.channelActive(ctx); + } + @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); + disconnectScheduler.cancel(key); + if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg; Channel channel = ctx.channel(); diff --git a/src/main/java/com/corundumstudio/socketio/scheduler/SchedulerKey.java b/src/main/java/com/corundumstudio/socketio/scheduler/SchedulerKey.java index 2bfb5bb..b2e84f9 100644 --- a/src/main/java/com/corundumstudio/socketio/scheduler/SchedulerKey.java +++ b/src/main/java/com/corundumstudio/socketio/scheduler/SchedulerKey.java @@ -15,16 +15,15 @@ */ package com.corundumstudio.socketio.scheduler; -import java.util.UUID; public class SchedulerKey { - public enum Type {POLLING, HEARBEAT_TIMEOUT, PING_TIMEOUT, ACK_TIMEOUT, UPGRADE_TIMEOUT}; + public enum Type {PING_TIMEOUT, ACK_TIMEOUT, UPGRADE_TIMEOUT}; private final Type type; - private final UUID sessionId; + private final Object sessionId; - public SchedulerKey(Type type, UUID sessionId) { + public SchedulerKey(Type type, Object sessionId) { this.type = type; this.sessionId = sessionId; }