Home Forums Support new TCPConnection WITHOUT being reused

Viewing 10 posts - 1 through 10 (of 16 total)
  • Author
    Posts
  • #3994
    Anonymous
    Inactive

    Hello,

    I have the scenario where I have multiple clients connected to the same listener, however I have just found that the clients are basically the same because the connection is reused.

    This is correct, according to https://networkcomms.net/api/html/Overload_NetworkCommsDotNet_Connections_TCP_TCPConnection_GetConnection.htm

    However, I really need to have different connections in order to receive replies for each one.

    How to to this?

    Some code I have (hope is enough):

    
    ...
     ConnectionInfo connInfo = new ConnectionInfo("127.0.0.1", port);
     m_Connection = TCPConnection.GetConnection(connInfo);
    ...
    
    public void Dummy()
    {
        var request = new BasicRequest(CommandType.Dummy);
        var msgReply = SendRequest(request);
    
        Log.Debug("reqId={0}, repId={1}", request.MessageId, msgReply.MessageId);
    }
    
    private BasicReply SendRequest(BasicRequest request, int timeout = 10000)
    {
       var result = m_Connection.SendReceiveObject<BasicRequest, BasicReply>("RequestReply", "Reply", timeout, request);
       return (result);
    }
    

    What I receive from the server, is basically this:

    
    Server log:
    REQUEST:: MessageID=4cafa7cab5b04055ab03283b2ee0679f; Type=2008; Client=127.0.0.1:61037
    REQUEST:: MessageID=682564f317444cc8ab35cd53a891514e; Type=2008; Client=127.0.0.1:61037
    REPLY:: MessageID=682564f317444cc8ab35cd53a891514e; Type=2008; Reply=5, Client=127.0.0.1:61037
    REPLY:: MessageID=4cafa7cab5b04055ab03283b2ee0679f; Type=2008; Reply=3, Client=127.0.0.1:61037
    
    and client log:
    2015-07-24 00:52:59,622 [Logic:12] DEBUG  reqId=4cafa7cab5b04055ab03283b2ee0679f, repId=682564f317444cc8ab35cd53a891514e
    2015-07-24 00:52:59,622 [Logic:06] DEBUG  reqId=682564f317444cc8ab35cd53a891514e, repId=682564f317444cc8ab35cd53a891514e
    

    So basically, the server receive both requests, and the replies get messed up! Message Ids do not match 🙁

    • This topic was modified 8 years, 9 months ago by .
    #4007
    Anonymous
    Inactive

    To achieve what you want I recommend you have the server listen on multiple ports and then get each client to connect to a specific port. This will force a new connection each time.

    Kind regards,
    Marc

    #4008
    Anonymous
    Inactive

    Hello Mark,

    It doesn’t make any sense for a communications framework not being able to have more than one client connected to the same server within the same application!

    Is this a real limitation of the framework?

    Regards
    Joao

    • This reply was modified 8 years, 9 months ago by .
    #4013
    Anonymous
    Inactive

    By the way, I currently have a working workaround in place

    
    lock (m_SyncRoot)
    {
        ConnectionInfo connInfo = new ConnectionInfo("127.0.0.1", port);
        while (NetworkComms.GetExistingConnection((EndPoint)connInfo.RemoteEndPoint, (EndPoint)connInfo.LocalEndPoint, connInfo.ConnectionType, connInfo.ApplicationLayerProtocol).Count != 0)
        {
            (connInfo.LocalEndPoint as IPEndPoint).Port = m_Rnd.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort);
        }
        m_Connection = TCPConnection.GetConnection(connInfo);
    
        LogInformation("Client using '{0}' endpoint", connInfo.LocalEndPoint);
    }
    

    However, this is not a “good looking” code. I would prefer to have native support.

    Regards
    Joao

    #4017
    Anonymous
    Inactive

    I love this job. Thanks

    #4026
    Anonymous
    Inactive

    Heya Jao,

    We are able to transmit data >1Gbps using just a single connection between clients which maxes out the physical hardware. We found that for specific high performance operations opening multiple connections actually increased contention and reduced maximum throughput. Having a single connection as such was therefore a performance optimisation not a limitation. If you could describe the scenario you require we will be happy to consider it. For the use case of requiring data priority we also have https://networkcomms.net/api/html/P_NetworkCommsDotNet_SendReceiveOptions_ReceiveHandlePriority.htm.

    Kind regards,
    Marc

    #4029
    Anonymous
    Inactive

    Hi Marc,

    I’ll explain my scenario the best I can:
    I Have one server running in port i.e. 7000. This server can address different data depending on one parameter of the message. If it has “Hello”, it will forward the request to a class “Hello” and allow it to process and return. If it receives “World”, it will forward the request to the “World” class and so forth.

    Basically, the main server acts like an entry point/router for the sub classes to handle the work.

    Then, I have the client.
    The client has multiple connections to the same server. Each connection is supposed to handle one and only one of the behaviours of the server, and, of course, each one will receive the reply that it is supposed to receive.

    The current implementation (without my workaround) is simply impossible. The replies will go to some client. It is almost random.

    Let me know if this description is enough.

    Regards
    Joao

    • This reply was modified 8 years, 8 months ago by .
    #4031
    Anonymous
    Inactive

    From what I understand everything you want to achieve can be done with different packet types. Each packet type has a dedicated packethandler which will direct the data to the required class? Why is this not suitable?

    #4032
    Anonymous
    Inactive

    What do you mean with packet type?
    Can you post an example?

    #4038
    Anonymous
    Inactive

    Please see the numerous examples included, these introduce the concept of having named packet types, each can be handled independently by the receiving client.

    Marc

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