Search in sources :

Example 1 with Packet

use of com.corundumstudio.socketio.protocol.Packet 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 2 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class BroadcastOperations method sendEvent.

public void sendEvent(String name, SocketIOClient excludedClient, Object... data) {
    Packet packet = new Packet(PacketType.MESSAGE);
    packet.setSubType(PacketType.EVENT);
    packet.setName(name);
    packet.setData(Arrays.asList(data));
    for (SocketIOClient client : clients) {
        if (client.getSessionId().equals(excludedClient.getSessionId())) {
            continue;
        }
        client.send(packet);
    }
    dispatch(packet);
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet)

Example 3 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class NamespaceClient method sendEvent.

@Override
public void sendEvent(String name, Object... data) {
    Packet packet = new Packet(PacketType.MESSAGE);
    packet.setSubType(PacketType.EVENT);
    packet.setName(name);
    packet.setData(Arrays.asList(data));
    send(packet);
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet)

Example 4 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class NamespaceClient method sendEvent.

@Override
public void sendEvent(String name, AckCallback<?> ackCallback, Object... data) {
    Packet packet = new Packet(PacketType.MESSAGE);
    packet.setSubType(PacketType.EVENT);
    packet.setName(name);
    packet.setData(Arrays.asList(data));
    send(packet, ackCallback);
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet)

Example 5 with Packet

use of com.corundumstudio.socketio.protocol.Packet in project netty-socketio by mrniko.

the class DecoderAckPacketTest method testDecode.

@Test
public void testDecode() throws IOException {
    Packet packet = decoder.decodePacket("6:::140", null);
    Assert.assertEquals(PacketType.ACK, packet.getType());
    Assert.assertEquals(140, (long) packet.getAckId());
//        Assert.assertTrue(packet.getArgs().isEmpty());
}
Also used : Packet(com.corundumstudio.socketio.protocol.Packet) Test(org.junit.Test)

Aggregations

Packet (com.corundumstudio.socketio.protocol.Packet)39 Test (org.junit.Test)27 ByteBuf (io.netty.buffer.ByteBuf)15 Namespace (com.corundumstudio.socketio.namespace.Namespace)2 AuthPacket (com.corundumstudio.socketio.protocol.AuthPacket)2 HandshakeData (com.corundumstudio.socketio.HandshakeData)1 SocketIOClient (com.corundumstudio.socketio.SocketIOClient)1 Transport (com.corundumstudio.socketio.Transport)1 HttpErrorMessage (com.corundumstudio.socketio.messages.HttpErrorMessage)1 JacksonJsonSupport (com.corundumstudio.socketio.protocol.JacksonJsonSupport)1 PacketDecoder (com.corundumstudio.socketio.protocol.PacketDecoder)1 ConnectMessage (com.corundumstudio.socketio.store.pubsub.ConnectMessage)1 NamespaceClient (com.corundumstudio.socketio.transport.NamespaceClient)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1