2

There is a server running on 192.168.0.10 we lost power and the server had to restart, the thing is our application have a function called StartReceive() that create a Socket then call a socket.Connect(IPEndPoint). But I get this error "No connection could be made because the target machine actively refused it "192.168.0.10:2131"" I am new at this company and I am the only one, every one is on leave for the next 2 weeks. I've gathered some information but nothing seems to fit together, I feel like I am missing a piece of the puzzle.

I've read these, but nothing helped me:

  1. http://csharp.net-informations.com/communications/connection.htm
  2. No connection could be made because the target machine actively refused it?
  3. https://www.codeproject.com/Questions/5332894/System-net-sockets-socketexception-no-connection-c
  4. https://learn.microsoft.com/en-us/answers/questions/626063/no-connection-could-be-made-because-the-target-mac

At the top of my class I have this:

public static string DBAvantage = "02"; 
 public static string PassAvantage = "PASSWORD";

List<string> lcommande = new List<string> { "LOGIN," + DBEngine.DBAvantage + ",OPERATEUR," + DBEngine.PassAvantage + "\n" };

These infos let me think that Advantage is a DB

When I the code run and it get to the function StartReceive(), it crash and I get this error "No connection could be made because the target machine actively refused it "192.168.0.10:2131""

private void StartRecieve()
        {
            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IPAddress hostadd = IPAddress.Parse("192.168.0.10");
            int port = Int32.Parse("2131");
            IPEndPoint EPhost = new IPEndPoint(hostadd, port);

            s.Connect(EPhost);

            int cnt = 0;
            string tmp = null;
            Byte[] firstb = new Byte[1];
            bool finish = false;
            while (!finish)
            {
                try
                {
                    Byte[] receive = new Byte[1];
                    int ret = s.Receive(receive);
                    if (ret > 0)
                    {
                        switch (receive[0])
                        {
                            case 11: //check start message
                                cnt = 0;
                                break;
                            case 10: // check end message
                                cnt = 0;
                                finish = HandleText(tmp);
                                tmp = null;
                                if (ncommande < lcommande.Count)
                                {
                                    Byte[] bBuf;
                                    string buf;

                                    buf = String.Format(lcommande[ncommande]);
                                    bBuf = ASCII.GetBytes(buf);
                                    s.Send(bBuf, 0, bBuf.Length, 0);
                                    ncommande++;
                                }
                                break;
                            default:
                                if (cnt == 0)
                                    firstb[0] = receive[0];
                                tmp += Encoding.ASCII.GetString(receive);
                                cnt++;
                                break;
                        }
                    }
                }
                catch
                {
                    if (!s.Connected)
                    {
                        break;
                    }
                }
            }
            s.Disconnect(true);
            t.Abort();
        }

I tried to look on internet what is running on port 2131. I found this: Port 2131 internet search result

I've been trying to search things about the service avantageb2b, but nothing comes out on internet. This is the only informations I've found. Is it possible to restart this service ? What can I do ? My guest is the power loss made the server restart but this service didn't restart has it should have been and when I try to listen at it, it can't.

Dolotboy
  • 21
  • 3
  • 1
    Is there any reason you're using raw sockets instead of TcpClient? But it sounds like there just isn't anything listening on port 2131... – Jon Skeet Aug 16 '23 at 16:03
  • This is not my code, this is one of my coworker who did this part. It was working fine for the last months/years and now it stopped working and Idk why. So the shouldn't be the problem. As I said my guest is the server is the problem – Dolotboy Aug 16 '23 at 16:05
  • 1
    Well yes, it sounds like the server isn't running - contrary to your very first sentence. (Or the server's firewall is blocking you...) – Jon Skeet Aug 16 '23 at 16:24
  • 1
    PLEASE tell me that `t` is not a `Thread` ... – Fildor Aug 16 '23 at 16:25
  • I already tried to add TCP/UDP inbound and outbound rule on port 2131 in the server and it didn't change anything. The server is running, I am currently connected to it via RDP. – Dolotboy Aug 16 '23 at 16:41
  • Well it seems the T is Thread, can you explain to me what does it do ? – Dolotboy Aug 16 '23 at 16:42
  • 1
    `t.Abort` is deprecated, doesn't work at all on .NET Core, and is overall a bad idea. Use `CancellationToken` and async functions. This code needs a complete rewrite to be honest. – Charlieface Aug 16 '23 at 16:50
  • A UDP rule won't cut it because the protocol is TCP. Also, not only the Serv**er** needs to run but also the Serv**ice** that listens on that port. – Fildor Aug 17 '23 at 04:40
  • And I second Charlieface: that code needs to be hauled into 2023. But better not open too many construction sites at once. First get it to connect again. – Fildor Aug 17 '23 at 04:43
  • The thing is I don't know what service runs on that port. As I said I found really little informations about what runs on this port. I would guess it is avantageb2b, but I searched how to restart this service and found nothing about it, which is the point to my question, does anyone know anything about this service – Dolotboy Aug 18 '23 at 19:51

0 Answers0