Home Forums Support Connection specific AppendShutdownHandler

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3955
    Anonymous
    Inactive

    Hi,
    I’m currently trying to create a sort of forwarder which listens on a port, then receive a certain packet which will tell him where to redirect next pacekts coming from the same client.

    Example:
    CLIENT tell GATEWAY that he needs to get to SERVER:serverport
    GATEWAY creates a connection to SERVER:serverport
    CLIENT sends packets to GATEWAY which sends them to SERVER
    SERVER sends back a response, which goes through the GATEWAY to the CLIENT.

    I had it working with Net.Sockets and I’m now changing to NetworkComms.

    The problem I’m facing is that when a connection from Gateway (client) to Server (listening server) is closed, the Gateway trigger the global callbacks for connection/disconnection:

    NetworkComms.AppendGlobalConnectionCloseHandler(ClientDisconnected);
    NetworkComms.AppendGlobalConnectionEstablishHandler(ClientConnected);

    Those callbacks are supposed to be only called when a client connect or disconnect on the Gateway

    This is the code i’m currently using to start the listener.

    NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions<ProtobufSerializer, , LZMACompressor>();
    NetworkComms.DefaultSendReceiveOptions.IncludePacketConstructionTime = NetworkComms.DefaultSendReceiveOptions.ReceiveHandlePriority = QueueItemPriority.AboveNormal;
    NetworkComms.AppendGlobalConnectionCloseHandler(SessionClosed);
    NetworkComms.AppendGlobalConnectionEstablishHandler(NewSessionConnected);
    NetworkComms.AppendGlobalIncomingPacketHandler<string>("ECHO", SocketCommands.HandleIncomingECHOPacket);
    Connection.StartListening(ConnectionType.TCP, new IPEndPoint(IPAddress.Any, 10000));

    I suppose this is like a “global” way of starting It?
    How do I start one then add those Connected/Disconnected handlers to just the listener?

    Thanks

    #3959
    Anonymous
    Inactive

    Create an instance of TCPConnectionListener and then use TCPConnectionListener.AppendIncomingPacketHandler.

    Once configured you can provide the listener to ConnectionListeners.StartListening

    Regards,
    Marc

    #3960
    Anonymous
    Inactive

    Thanks for the answer,
    What i already do is this:

    TCPConnectionListener listener = new TCPConnectionListener(new SendReceiveOptions<ProtobufSerializer, LZMACompressor>(), ApplicationLayerProtocolStatus.Enabled, true);
    
    NetworkComms.AppendGlobalConnectionCloseHandler(ClientDisconnected);
    NetworkComms.AppendGlobalConnectionEstablishHandler(ClientConnected);
    
    listener.AppendIncomingPacketHandler<string>("PING", HandleIncomingPINGPacket);
    listener.AppendIncomingPacketHandler<string>("DEST", HandleIncomingDESTPacket);
    listener.AppendIncomingPacketHandler<byte[]>("DATA", HandleIncomingDATAPacket);
    
    Connection.StartListening(listener, new IPEndPoint(IPAddress.Any, 19000));

    Basically I would like to make those ClientConnected and ClientDisconnected related to this listener, instead of make them global.
    The reason why is because I got a client in the same application, and when it connects or disconnects It triggers the same methods of this listener.

    #3967
    Anonymous
    Inactive

    I don’t think this is possible directly. There is currently no listener.AppendConnectionCloseHandler() method. One work around is to check the IP address in the global AppendGlobalConnectionEstablishHandler and then add a connection specific close handler there.

    Regards,
    Marc

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.