Home Forums Support Problem with single server/multiple clients

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

    Hello!

    I have written a toy client/server application, given below:

    Server:

    
    using System;
    using NetworkCommsDotNet;
    using NetworkCommsDotNet.Connections;
    
    namespace NetworkCommsTestServer
    {
    	class Program
    	{
    		static void Main(string[] args)
    		{
    
    			//Trigger the method PrintIncomingMessage when a packet of type 'Message' is received
                //We expect the incoming object to be a string which we state explicitly by using <string>
                NetworkComms.AppendGlobalIncomingPacketHandler<string>("Message", PrintIncomingMessage);
    			NetworkComms.AppendGlobalConnectionEstablishHandler(OnConnectionEstablished);
    			NetworkComms.AppendGlobalConnectionCloseHandler(OnConnectionClosed);
                //Start listening for incoming connections
                Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 4000));
     
                //Print out the IPs and ports we are now listening on
                Console.WriteLine("Server listening for TCP connection on:");
                foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP))
                    Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port);
     
                //Let the user close the server
                Console.WriteLine("\nPress any key to close server.");
                Console.ReadKey(true);
     
                //We have used NetworkComms so we should ensure that we correctly call shutdown
                NetworkComms.Shutdown();
            }
    
    		private static void OnConnectionClosed(Connection connection)
    		{
    			Console.WriteLine("Connection closed!");
    		}
    
    		private static void OnConnectionEstablished(Connection connection)
    		{
    			Console.WriteLine("Connection established!");
    		}
     
            /// <summary>
            /// Writes the provided message to the console window
            /// </summary>
            /// <param name="header">The packet header associated with the incoming message</param>
            /// <param name="connection">The connection used by the incoming message</param>
            /// <param name="message">The message to be printed to the console</param>
            private static void PrintIncomingMessage(PacketHeader header, Connection connection, string message)
            {	
    			Console.WriteLine(message);
            }
    	}
    }
    

    Client:

    
    using System;
    using System.Diagnostics;
    using System.Net;
    using System.Threading;
    using NetworkCommsDotNet;
    using NetworkCommsDotNet.Connections.TCP;
    using NetworkCommsDotNet.DPSBase;
    
    namespace NetworkCommsTestClient
    {
        class Program
        {
            private static string Server = "localhost";
            private static int Port = 4000;
            private static string SlaveNameFormat = "Slave{0}";
    
            static void Main(string[] args)
            {
                var slaveId = Process.GetCurrentProcess().Id;
                var endpoint = GetIPEndPointFromHostName(Server, Port);
                var connection = TCPConnection.GetConnection(new ConnectionInfo(endpoint));
                var slaveName = string.Format(SlaveNameFormat, slaveId);
    
                connection.SendObject("Message", string.Format("{0} reporting for duty!", slaveName));
                Thread.Sleep(5000);
                connection.SendObject("Message", string.Format("{0} unregistering duty!", slaveName));
                Thread.Sleep(5000);
            }
    
            private static IPEndPoint GetIPEndPointFromHostName(string hostName, int port)
            {
                var addresses = Dns.GetHostAddresses(hostName);
                if (addresses.Length == 0)
                {
                    throw new ArgumentException(
                        "Unable to retrieve address from specified host name.",
                        "hostName"
                        );
                }
                return new IPEndPoint(addresses[0], port); // Port gets validated here.
            }
        }
    }
    

    I run both the server and multiple instances of the client in separate processes on my local machine (running Windows 8), started pretty much simultaneously using a batch script. If the number of client processes is around 10 or less, everything runs as expected. But if the number of clients is 20 or more, all clients throw the following:

    
    Unhandled Exception: NetworkCommsDotNet.ConnectionSetupException: Timeout waiting for server connnectionInfo from [TCP-E-I] [::1]:26528 -> ::1]:4000. Connection created at 12:22:52.192, its now 12:23:03.8
       at NetworkCommsDotNet.Connections.Connection.ConnectionHandshake() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\ConnectionCreate.cs:line 246
       at NetworkCommsDotNet.Connections.TCP.TCPConnection.EstablishConnectionSpecific() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnection.cs:line 143
       at NetworkCommsDotNet.Connections.Connection.EstablishConnection() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\ConnectionCreate.cs:line 171
       at NetworkCommsDotNet.Connections.TCP.TCPConnection.GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, TcpClient tcpClient, Boolean establishIfRequired, SSLOptions sslOptions) in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionStatic.cs:line 171
       at NetworkCommsDotNet.Connections.TCP.TCPConnection.GetConnection(ConnectionInfo connectionInfo, Boolean establishIfRequired) in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionStatic.cs:line 49
       at NetworkCommsTestClient.Program.Main(String[] args) in c:\RB\src\NetworkCommsTesting\Program.cs:line 22
    

    OnConnectionClosed() is the only callback called on the server (once for each client) and it spews a variety of exceptions, including:

    
    Exception:Thrown: "Timeout waiting for client connectionInfo with [TCP-E-I] [::1]:4000 -> [::1]:26508 (7Vh_NvOQzkiPQR7JHkipuw). Connection created at 12:22:51.494, its now 12:23:03.6" (NetworkCommsDotNet.ConnectionSetupException)
    A NetworkCommsDotNet.ConnectionSetupException was thrown: "Timeout waiting for client connectionInfo with [TCP-E-I] [::1]:4000 -> [::1]:26508 (7Vh_NvOQzkiPQR7JHkipuw). Connection created at 12:22:51.494, its now 12:23:03.6"
    Time: 7/3/2014 12:23:03 PM
    Thread:<No Name>[23188]
    
    >   NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.Connection.ConnectionHandshake()  C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.TCP.TCPConnection.EstablishConnectionSpecific()   C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.Connection.EstablishConnection()  C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.TCP.TCPConnection.GetConnection(NetworkCommsDotNet.ConnectionInfo connectionInfo = {unknown}, NetworkCommsDotNet.SendReceiveOptions defaultSendReceiveOptions = {unknown}, System.Net.Sockets.TcpClient tcpClient = {unknown}, bool establishIfRequired = {unknown}, NetworkCommsDotNet.Connections.TCP.SSLOptions sslOptions = {unknown})    C#
        NetworkCommsDotNetComplete.dll!<>c__DisplayClass1.AnonymousMethod(object obj = {unknown})   C#
    
    
    Exception:Thrown: "Cannot access a disposed object." (System.ObjectDisposedException)
    A System.ObjectDisposedException was thrown: "Cannot access a disposed object."
    Time: 7/3/2014 12:23:03 PM
    Thread:Worker Thread[14192]
    
    >   System.dll!System.Net.Sockets.Socket.Disconnect(bool reuseSocket = {unknown})   C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.TCP.TCPConnection.CloseConnectionSpecific(bool closeDueToError = {unknown}, int logLocation = {unknown})  C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.Connection.CloseConnection(bool closeDueToError = {unknown}, int logLocation = {unknown}) C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.Connection.EstablishConnection()  C#
        NetworkCommsDotNetComplete.dll!NetworkCommsDotNet.Connections.TCP.TCPConnection.GetConnection(NetworkCommsDotNet.ConnectionInfo connectionInfo = {unknown}, NetworkCommsDotNet.SendReceiveOptions defaultSendReceiveOptions = {unknown}, System.Net.Sockets.TcpClient tcpClient = {unknown}, bool establishIfRequired = {unknown}, NetworkCommsDotNet.Connections.TCP.SSLOptions sslOptions = {unknown})    C#
        NetworkCommsDotNetComplete.dll!<>c__DisplayClass1.AnonymousMethod(object obj = {unknown})   C#
    
    
    Exception:Thrown: "An established connection was aborted by the software in your host machine" (System.Net.Sockets.SocketException)
    A System.Net.Sockets.SocketException was thrown: "An established connection was aborted by the software in your host machine"
    Time: 7/3/2014 12:23:04 PM
    Thread:Worker Thread[15928]
    
    >   System.dll!System.Net.Sockets.Socket.BeginSend(byte[] buffer = {unknown}, int offset = {unknown}, int size = {unknown}, System.Net.Sockets.SocketFlags socketFlags = {unknown}, System.AsyncCallback callback = {unknown}, object state = {unknown})    C#
        System.dll!System.Net.Sockets.NetworkStream.BeginWrite(byte[] buffer = {unknown}, int offset = {unknown}, int size = {unknown}, System.AsyncCallback callback = {unknown}, object state = {unknown})    C#
        NetworkCommsDotNetComplete.dll!<>c__DisplayClass2.AnonymousMethod(System.IAsyncResult ar = {unknown})   C#
        [External Code] 
    

    What could cause this? Surely the library supports more than 20 simultaneous connections?

    Thanks in advance,
    Lucas

    #2730
    Anonymous
    Inactive

    I have found that setting NetworkComms.ConnectionEstablishTimeoutMS sufficiently high on both the client and server will allow the example above to work, although it takes a long time for most connections to establish (the more clients, the longer). It was set to 10000 ms by default, instead of the 30000 ms documented in the API reference. Even so, it seems strange to me that many simultaneous connections should incur such a hefty delay. Is this normal? And if not, how can I prevent it?

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

    Heya Dementati,

    Interesting problem as this scenario is quite well tested. There is an overhead to establishing/closing connections so I would be interested to know what happens if the client does not close after 10 seconds and instead stays open for a few minutes.

    Regards,
    Marc

    #2742
    Anonymous
    Inactive

    Changing the delay between sending the first and second message from 5s to 180s made no obvious difference. When connecting with 20 clients, 13 disconnected almost immediately and the seven remaining ones took a long time to establish connections and send the first message. The exceptions thrown were the same. Delaying for three minutes before sending the first message made no difference either.

    #2747
    Anonymous
    Inactive

    Ok thanks for the feedback. We will investigate further using the samples you have provided.

    Kind regards,
    Marc

    #2755
    Anonymous
    Inactive

    Some quick testing was not able to reproduce your bug. Could you please also provide the batch script so that we can recreate the situation accuracy.

    Regards,
    Marc

    #2776
    Anonymous
    Inactive

    Sure.

    for /l %%i in (1, 1, 100) do start "title of the process" "NetworkCommsTesting.exe"

    #2787
    Anonymous
    Inactive

    So, the very first time I ran your example it worked flawlessly:

    Slave7328 reporting for duty!
    Slave7328 unregistering duty!
    Connection closed!
    Connection established!
    Slave4532 reporting for duty!
    Connection established!
    Slave444 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Slave7956 reporting for duty!
    Connection established!
    Slave1344 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Slave7208 reporting for duty!
    Connection established!
    Slave8056 reporting for duty!
    Slave4592 reporting for duty!
    Slave8072 reporting for duty!
    Slave1744 reporting for duty!
    Slave6648 reporting for duty!
    Slave4328 reporting for duty!
    Connection established!
    Connection established!
    Slave6908 reporting for duty!
    Slave8176 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Slave7556 reporting for duty!
    Slave7188 reporting for duty!
    Slave7104 reporting for duty!
    Connection established!
    Slave8004 reporting for duty!
    Slave7624 reporting for duty!
    Slave7692 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Slave5000 reporting for duty!
    Slave4532 unregistering duty!
    Connection established!
    Connection established!
    Slave7468 reporting for duty!
    Slave8424 reporting for duty!
    Slave8352 reporting for duty!
    Slave3640 reporting for duty!
    Connection established!
    Slave444 unregistering duty!
    Slave8680 reporting for duty!
    Slave7056 reporting for duty!
    Slave2320 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Slave7956 unregistering duty!
    Slave8640 reporting for duty!
    Slave8240 reporting for duty!
    Slave1344 unregistering duty!
    Connection established!
    Connection established!
    Slave7208 unregistering duty!
    Connection established!
    Slave8056 unregistering duty!
    Connection established!
    Connection established!
    Slave4592 unregistering duty!
    Slave8628 reporting for duty!
    Slave8072 unregistering duty!
    Slave8820 reporting for duty!
    Slave1744 unregistering duty!
    Slave7272 reporting for duty!
    Slave8884 reporting for duty!
    Connection established!
    Slave6648 unregistering duty!
    Slave4328 unregistering duty!
    Slave8804 reporting for duty!
    Slave8256 reporting for duty!
    Slave8984 reporting for duty!
    Slave8496 reporting for duty!
    Slave7716 reporting for duty!
    Slave9184 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Slave8176 unregistering duty!
    Slave6908 unregistering duty!
    Slave9396 reporting for duty!
    Slave9500 reporting for duty!
    Connection established!
    Connection established!
    Slave9532 reporting for duty!
    Connection established!
    Slave9556 reporting for duty!
    Slave9604 reporting for duty!
    Connection established!
    Connection established!
    Slave9732 reporting for duty!
    Slave9796 reporting for duty!
    Connection established!
    Slave10048 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Slave8220 reporting for duty!
    Connection established!
    Slave10312 reporting for duty!
    Slave7188 unregistering duty!
    Slave7556 unregistering duty!
    Slave7104 unregistering duty!
    Slave10364 reporting for duty!
    Slave8004 unregistering duty!
    Slave7624 unregistering duty!
    Slave10400 reporting for duty!
    Connection established!
    Slave7692 unregistering duty!
    Slave10500 reporting for duty!
    Connection established!
    Slave5000 unregistering duty!
    Connection closed!
    Connection established!
    Slave10528 reporting for duty!
    Slave7468 unregistering duty!
    Slave8424 unregistering duty!
    Connection established!
    Slave8352 unregistering duty!
    Slave3640 unregistering duty!
    Connection closed!
    Slave10660 reporting for duty!
    Slave7056 unregistering duty!
    Slave8680 unregistering duty!
    Slave10724 reporting for duty!
    Connection established!
    Slave10772 reporting for duty!
    Connection established!
    Slave2320 unregistering duty!
    Connection established!
    Slave10928 reporting for duty!
    Connection established!
    Slave11052 reporting for duty!
    Slave11096 reporting for duty!
    Connection established!
    Slave11176 reporting for duty!
    Connection established!
    Connection closed!
    Slave8640 unregistering duty!
    Connection established!
    Connection closed!
    Slave8240 unregistering duty!
    Connection closed!
    Connection closed!
    Slave10376 reporting for duty!
    Connection closed!
    Slave10820 reporting for duty!
    Connection established!
    Connection closed!
    Connection closed!
    Slave8820 unregistering duty!
    Slave8628 unregistering duty!
    Slave8884 unregistering duty!
    Slave9408 reporting for duty!
    Connection closed!
    Connection established!
    Slave7272 unregistering duty!
    Connection closed!
    Connection established!
    Slave8804 unregistering duty!
    Slave8256 unregistering duty!
    Slave8984 unregistering duty!
    Slave8496 unregistering duty!
    Slave7716 unregistering duty!
    Slave9928 reporting for duty!
    Slave11460 reporting for duty!
    Slave9184 unregistering duty!
    Slave11632 reporting for duty!
    Connection established!
    Connection established!
    Connection established!
    Connection established!
    Slave11732 reporting for duty!
    Slave11900 reporting for duty!
    Connection closed!
    Connection established!
    Connection closed!
    Slave12200 reporting for duty!
    Slave12028 reporting for duty!
    Slave9396 unregistering duty!
    Slave9500 unregistering duty!
    Connection established!
    Connection established!
    Slave12268 reporting for duty!
    Connection established!
    Slave9532 unregistering duty!
    Slave12312 reporting for duty!
    Connection established!
    Slave10316 reporting for duty!
    Slave12412 reporting for duty!
    Slave9556 unregistering duty!
    Connection established!
    Slave9604 unregistering duty!
    Connection established!
    Slave12532 reporting for duty!
    Connection established!
    Slave12672 reporting for duty!
    Connection established!
    Slave9732 unregistering duty!
    Slave12972 reporting for duty!
    Connection established!
    Slave9796 unregistering duty!
    Slave13100 reporting for duty!
    Connection established!
    Slave10048 unregistering duty!
    Slave13184 reporting for duty!
    Connection established!
    Connection established!
    Slave13268 reporting for duty!
    Slave11492 reporting for duty!
    Connection established!
    Slave8220 unregistering duty!
    Slave4776 reporting for duty!
    Connection established!
    Slave13424 reporting for duty!
    Slave10312 unregistering duty!
    Connection closed!
    Connection closed!
    Connection closed!
    Slave10364 unregistering duty!
    Connection closed!
    Slave13560 reporting for duty!
    Connection closed!
    Connection established!
    Slave10400 unregistering duty!
    Slave13644 reporting for duty!
    Connection established!
    Connection closed!
    Connection established!
    Slave10500 unregistering duty!
    Connection established!
    Slave13756 reporting for duty!
    Connection closed!
    Connection established!
    Slave13860 reporting for duty!
    Connection established!
    Slave13972 reporting for duty!
    Slave10528 unregistering duty!
    Connection closed!
    Connection established!
    Slave14080 reporting for duty!
    Connection closed!
    Connection closed!
    Connection established!
    Connection established!
    Connection closed!
    Slave14208 reporting for duty!
    Connection closed!
    Connection closed!
    Slave10660 unregistering duty!
    Slave12704 reporting for duty!
    Slave13060 reporting for duty!
    Connection established!
    Slave14384 reporting for duty!
    Slave14496 reporting for duty!
    Slave10724 unregistering duty!
    Connection established!
    Connection established!
    Connection established!
    Slave10772 unregistering duty!
    Connection established!
    Slave14620 reporting for duty!
    Connection established!
    Slave14752 reporting for duty!
    Connection closed!
    Slave15008 reporting for duty!
    Slave14884 reporting for duty!
    Slave15144 reporting for duty!
    Slave15272 reporting for duty!
    Slave10928 unregistering duty!
    Slave11052 unregistering duty!
    Slave11096 unregistering duty!
    Slave11176 unregistering duty!
    Connection closed!
    Connection closed!
    Slave10376 unregistering duty!
    Slave10820 unregistering duty!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Slave9408 unregistering duty!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Slave9928 unregistering duty!
    Slave11460 unregistering duty!
    Connection closed!
    Slave11632 unregistering duty!
    Slave11732 unregistering duty!
    Slave11900 unregistering duty!
    Slave12028 unregistering duty!
    Slave12200 unregistering duty!
    Connection closed!
    Connection closed!
    Slave12268 unregistering duty!
    Connection closed!
    Slave12312 unregistering duty!
    Slave10316 unregistering duty!
    Slave12412 unregistering duty!
    Connection closed!
    Connection closed!
    Slave12532 unregistering duty!
    Slave12672 unregistering duty!
    Connection closed!
    Slave12972 unregistering duty!
    Connection closed!
    Slave13100 unregistering duty!
    Connection closed!
    Slave13184 unregistering duty!
    Slave13268 unregistering duty!
    Slave11492 unregistering duty!
    Connection closed!
    Slave4776 unregistering duty!
    Slave13424 unregistering duty!
    Connection closed!
    Connection closed!
    Slave13560 unregistering duty!
    Connection closed!
    Slave13644 unregistering duty!
    Connection closed!
    Slave13756 unregistering duty!
    Slave13860 unregistering duty!
    Slave13972 unregistering duty!
    Connection closed!
    Slave14080 unregistering duty!
    Slave14208 unregistering duty!
    Connection closed!
    Slave12704 unregistering duty!
    Slave13060 unregistering duty!
    Slave14384 unregistering duty!
    Slave14496 unregistering duty!
    Connection closed!
    Connection closed!
    Slave14620 unregistering duty!
    Slave14752 unregistering duty!
    Slave15008 unregistering duty!
    Slave14884 unregistering duty!
    Slave15144 unregistering duty!
    Slave15272 unregistering duty!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!
    Connection closed!

    Every subsequent run I ended up with the error you described. My suspicion at this point is that this may be an operating system limitation. In one of our own test cases we start 50k connections simultaneously in a very similar way to yours but all within a maximum of two processes.

    I will keep investigating as I am interested to know what the root cause of this is. I do however have to ask why you are interested in this particular use case. It is probably a bad system design to require many independent processes to start within such a short space of time.

    Regards,
    Marc

    #2849
    Anonymous
    Inactive

    We need to communicate with about 100 cloud-based VPN servers, and send messages to them simultaneously.

    I find it interesting (and frankly, quite arrogant) that you question our system design instead of fixing this very common use case. Is this really how you do business?

    Let me know if you have resolved this bug (it’s been over 3 weeks). Otherwise we want an immediate refund and will look for a more suitable network library.

    Thank you.

    #2851
    Anonymous
    Inactive

    The use case you have just described is not the same as the one in which you would like to deploy NetworkComms.Net. In particular the started processes run within different execution environments (i.e. oranges and apples). We have many developers using NetworkComms.Net to communicate with thousands of servers, all simultaneously, without issue.

    Any good developer worth their salt is typically happy to justify their design structure, just as we have been happy to do, many times, over the past several years. My questions are important as they allow me to better understand you desired goals, I have absolutely no desire to offend anyone.

    I will try to prioritise this issue over the next few days but as I alluded to in my previous post I believe there is a high probability that this is caused due to an OS limitation. If you attempt to create 100K+ simultaneous connections from within only two processes, i.e. one client, one server, there is no issue. The executed code in both circumstances is identical, again supporting the idea of an OS limitation.

    Regards,
    Marc

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