- This topic has 15 replies, 4 voices, and was last updated 9 years, 3 months ago by Anonymous.
-
AuthorPosts
-
July 24, 2015 at 01:33 #3994AnonymousInactive
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 9 years, 4 months ago by .
July 27, 2015 at 12:30 #4007AnonymousInactiveTo 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,
MarcJuly 27, 2015 at 12:33 #4008AnonymousInactiveHello 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 9 years, 4 months ago by .
July 27, 2015 at 14:17 #4013AnonymousInactiveBy 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
JoaoJuly 28, 2015 at 06:16 #4017AnonymousInactiveI love this job. Thanks
August 3, 2015 at 23:02 #4026AnonymousInactiveHeya 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,
MarcAugust 3, 2015 at 23:13 #4029AnonymousInactiveHi 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 9 years, 3 months ago by .
August 3, 2015 at 23:23 #4031AnonymousInactiveFrom 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?
August 3, 2015 at 23:32 #4032AnonymousInactiveWhat do you mean with packet type?
Can you post an example?August 7, 2015 at 21:30 #4038AnonymousInactivePlease see the numerous examples included, these introduce the concept of having named packet types, each can be handled independently by the receiving client.
Marc
-
AuthorPosts
- You must be logged in to reply to this topic.