Home Forums Support Unable to create a TCP connection

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

    I have one windows service that is creating a TCP listener on port 10000 liek this:

    TCPConnection.StartListening(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10000));

    …and another service that is attempting to connect to it using the following code:

    NetworkComms.SendObject("Plugin", "192.168.1.147", 10000, MyMessageToSend);

    This connection seems to fail with the following error:

    Error during TCP connection establish with destination ([TCP] Local -> 192.167.1.147:10000). Destination may not be listening or connect timed out. System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
       at NetworkCommsDotNet.TCPConnection.ConnectSocket() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionCreate.cs:line 336

    Any help on what may be causing this error would be great. I tinkered around with the firewall on both machines, but Wasn’t able to get it to connect at all.

    #1394
    Anonymous
    Inactive

    TCPConnection.StartListening(new IPEndPoint(IPAddress.Parse(“192.168.1.147”), 10000));

    #1395
    Anonymous
    Inactive

    Thank you for the reply, but that did not seem to make any difference. The error occurs on the attempted connection, not when setting up the listener.

    #1397
    Anonymous
    Inactive

    ServerCode

    IPEndPoint thePoint = new IPEndPoint(IPAddress.Parse(“192.168.1.147”), 10000);

    TCPConnection.StartListening(thePoint, false);

    Client Code

    ConnectionInfo connInfo = new ConnectionInfo(“192.168.1.147”, 10000);

    Connection newTcpConnection = TCPConnection.GetConnection(connInfo);

    #1399
    Anonymous
    Inactive

    Heyup Guys,

    Many thanks for the help msdc123. The following code is correct for listening on port 10000:

    TCPConnection.StartListening(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10000));

    but it is important to know that if port 10000 is unavailable, NetworkComms.Net will automatically fail over to a random port. If a port is unavailable and you would rather have an exception when calling TCPConnection.StartListening.

    The solution is to check which port was used on the server:

    Console.WriteLine("Listening for messages on:");
    foreach (System.Net.IPEndPoint localEndPoint in Connection.ExistingLocalListenEndPoints(ConnectionType.TCP)) 
        Console.WriteLine("{0}:{1}", localEndPoint.Address, localEndPoint.Port);
    

    Once you have confirmed the correct listening port, if you still have problems, please post back.

    Regards,
    Marc

    #1403
    Anonymous
    Inactive

    I made a slight change that msdc123 posted to have my client use the following:

    Connection newTcpConnection = TCPConnection.GetConnection(new ConnectionInfo("192.168.1.147", 10000));
    newTcpConnection.SendObject("Plugin", myObject);

    I also used the same code snippet from one of the tutorials to get the addresses and port that the server is listening on and i get the following output:

    Service listening for TCP connection on: fe80::5efe:192.168.1.147%10:10000
    Service listening for TCP connection on: fe80::186f:3e8a:cd51:7732%9:10000
    Service listening for TCP connection on: 2001:0:5ef5:79fb:186f:3e8a:cd51:7732:10000
    Service listening for TCP connection on: 127.0.0.1:10000
    Service listening for TCP connection on: ::1:10000
    Service listening for TCP connection on: 192.168.1.147:10000
    Service listening for TCP connection on: fe80::50e3:36de:8e19:fd02%3:10000
    Service listening for TCP connection on: fe80::4810:e1e5:8958:860c%4:10000
    Service listening for TCP connection on: fe80::f03a:5a2:9fa3:c9f9%6:10000
    Service listening for TCP connection on: fe80::acac:cf14:e233:959b%7:10000

    I see the address and port I am trying to connect with in that list so to me it seems like it should be working but I still get the following error:

    DPSBase.ConnectionSetupException: Error during TCP connection establish with destination ([TCP] Local -> 192.167.1.147:10000). Destination may not be listening or connect timed out. System.NullReferenceException: Object reference not set to an instance of an object.
       at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
       at NetworkCommsDotNet.TCPConnection.ConnectSocket() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionCreate.cs:line 336
       at NetworkCommsDotNet.TCPConnection.ConnectSocket() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionCreate.cs:line 349
       at NetworkCommsDotNet.TCPConnection.EstablishConnectionSpecific() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionCreate.cs:line 185
       at NetworkCommsDotNet.Connection.EstablishConnection() in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\ConnectionCreate.cs:line 150
       at NetworkCommsDotNet.TCPConnection.GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, TcpClient tcpClient, Boolean establishIfRequired) in c:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\NetworkCommsDotNet\Connection\TCP\TCPConnectionCreate.cs:line 142
       at OSAE.ClientService.ClientService.LoadPlugins() in c:\Users\Brian\Developement\Open Source Automation\Services\ClientService\ClientService.cs:line 205
    #1405
    Anonymous
    Inactive

    can you tell me your .net framework version.

    #1407
    Anonymous
    Inactive

    I am using .NET 4.0. Both my Client and server are built using 4.0 and I am using the 4.0 version of the networkcomms dll

    #1408
    Anonymous
    Inactive

    I don’t konw why ,my code works fine in my computer.

    If you are convenient,you can send the project to my email wenjie5816@yhaoo.com .

    I will test it

    #1410
    Anonymous
    Inactive

    I have narrowed the problem down a bit. I took the getting strated tutorial to create the client console application and I able able to successfully send a TCP message to my windows service that is has the TCP listener started.

    The problem is obviously with my client. I am a little lost on what to try since I am using exactly the same line of code as the tutorial’s console app.

    When my server gets the message from the console application it logs it as such:

    A message was recieved from [TCP] 192.168.1.147:10000 -> 192.168.1.101:2719 (cRsAB8gSbEqRdU-FRjlPZg) which said 'This is message #1'.

    The error from my client has this:

    Error during TCP connection establish with destination ([TCP] Local -> 192.167.1.147:10000)

    It looks like maybe the connection is messed up somehow?

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