Search in sources :

Example 1 with NamespaceClient

use of com.corundumstudio.socketio.transport.NamespaceClient in project netty-socketio by mrniko.

the class ClientHead method onChannelDisconnect.

public void onChannelDisconnect() {
    cancelPingTimeout();
    disconnected.set(true);
    for (NamespaceClient client : namespaceClients.values()) {
        client.onDisconnect();
    }
    for (TransportState state : channels.values()) {
        if (state.getChannel() != null) {
            clientsBox.remove(state.getChannel());
        }
    }
}
Also used : NamespaceClient(com.corundumstudio.socketio.transport.NamespaceClient)

Example 2 with NamespaceClient

use of com.corundumstudio.socketio.transport.NamespaceClient in project netty-socketio by mrniko.

the class InPacketHandler method channelRead0.

@Override
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, PacketsMessage message) throws Exception {
    ByteBuf content = message.getContent();
    ClientHead client = message.getClient();
    if (log.isTraceEnabled()) {
        log.trace("In message: {} sessionId: {}", content.toString(CharsetUtil.UTF_8), client.getSessionId());
    }
    while (content.isReadable()) {
        try {
            Packet packet = decoder.decodePackets(content, client);
            if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) {
                return;
            }
            Namespace ns = namespacesHub.get(packet.getNsp());
            if (ns == null) {
                if (packet.getSubType() == PacketType.CONNECT) {
                    Packet p = new Packet(PacketType.MESSAGE);
                    p.setSubType(PacketType.ERROR);
                    p.setNsp(packet.getNsp());
                    p.setData("Invalid namespace");
                    client.send(p);
                    return;
                }
                log.debug("Can't find namespace for endpoint: {}, sessionId: {} probably it was removed.", packet.getNsp(), client.getSessionId());
                return;
            }
            if (packet.getSubType() == PacketType.CONNECT) {
                client.addNamespaceClient(ns);
            }
            NamespaceClient nClient = client.getChildClient(ns);
            if (nClient == null) {
                log.debug("Can't find namespace client in namespace: {}, sessionId: {} probably it was disconnected.", ns.getName(), client.getSessionId());
                return;
            }
            packetListener.onPacket(packet, nClient, message.getTransport());
        } catch (Exception ex) {
            String c = content.toString(CharsetUtil.UTF_8);
            log.error("Error during data processing. Client sessionId: " + client.getSessionId() + ", data: " + c, ex);
            throw ex;
        }
    }
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) NamespaceClient(com.corundumstudio.socketio.transport.NamespaceClient) ByteBuf(io.netty.buffer.ByteBuf) Namespace(com.corundumstudio.socketio.namespace.Namespace)

Example 3 with NamespaceClient

use of com.corundumstudio.socketio.transport.NamespaceClient in project netty-socketio by mrniko.

the class ClientHead method addNamespaceClient.

public NamespaceClient addNamespaceClient(Namespace namespace) {
    NamespaceClient client = new NamespaceClient(this, namespace);
    namespaceClients.put(namespace, client);
    return client;
}
Also used : NamespaceClient(com.corundumstudio.socketio.transport.NamespaceClient)

Aggregations

NamespaceClient (com.corundumstudio.socketio.transport.NamespaceClient)3 Namespace (com.corundumstudio.socketio.namespace.Namespace)1 Packet (com.corundumstudio.socketio.protocol.Packet)1 ByteBuf (io.netty.buffer.ByteBuf)1