- This topic has 3 replies, 2 voices, and was last updated 9 years, 5 months ago by Anonymous.
-
AuthorPosts
-
July 6, 2015 at 19:18 #3955AnonymousInactive
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
July 7, 2015 at 21:56 #3959AnonymousInactiveCreate an instance of
TCPConnectionListener
and then useTCPConnectionListener.AppendIncomingPacketHandler
.Once configured you can provide the listener to
ConnectionListeners.StartListening
Regards,
MarcJuly 7, 2015 at 23:18 #3960AnonymousInactiveThanks 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.July 12, 2015 at 20:43 #3967AnonymousInactiveI 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 -
AuthorPosts
- You must be logged in to reply to this topic.