logo elektroda
logo elektroda
X
logo elektroda

[Solved] C # - Could not connect because target computer actively refused it

DDoS132 15909 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18294670
    DDoS132
    Level 8  
    Good day. I'm having a problem because the Client won't connect to the server. When the server listens on the port, e.g. 8061, I set the Client to the same port, but when I click the submit button to send the message to the server, an error appears:
    System.Net.Sockets.SocketException: „Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia 192.168.1.103:8061”
    Client:
    Code: C#
    Log in, to see the code

    Server:
    Code: C#
    Log in, to see the code
  • ADVERTISEMENT
  • #2 18294847
    Dżyszla
    Level 42  
    Either listening does not start at all (check netstat -an) or the firewall is blocking.
  • ADVERTISEMENT
  • #3 18295408
    DDoS132
    Level 8  
    Dżyszla wrote:
    Either listening does not start at all (check netstat -an) or the firewall is blocking.


    While enabling the listening device, the Firewall asked whether to allow the program to do so and I indicated that it should do so. VS 2019 marks the error when clicking the Submit button in the line where there is TcpClient client = new TcpClient (serverIP, port);
  • ADVERTISEMENT
  • #4 18295439
    Dżyszla
    Level 42  
    Nevertheless, check that there is actually a watch. Do you run the server normally or from the debugger?
    In general - why the option to enter an address in the server? After all, he must always have localhost / 127.0.0.1. And I would just use IPAddress.Parse ("127.0.0.1") instead of asking the DNS. I also understand that in the server console you let it go further (Read - rather unnecessary at all).
  • ADVERTISEMENT
  • #5 18295478
    DDoS132
    Level 8  
    Dżyszla wrote:
    Nevertheless, check that there is actually a watch. Do you run the server normally or from the debugger?
    In general - why the option to enter an address in the server? After all, he must always have localhost / 127.0.0.1. And I would just use IPAddress.Parse ("127.0.0.1") instead of asking the DNS. I also understand that in the server console you let it go further (Read - rather unnecessary at all).


    I made the option of adding my own IP so that later I could connect computers from outside the network. (By port forwarding, or ngroka or hamachi). I set up what you said and in netstat you could see 127.0.0.1:9081 (this is the port I created this time) LISTENING, but there is another problem. When I send a message from the Client, the server receives nothing. After doing netstat -an, I saw something like this again.
      TCP    127.0.0.1:9081         0.0.0.0:0              LISTENING                                                          TCP    127.0.0.1:9081         127.0.0.1:2531         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2532         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2540         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2541         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2542         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2543         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2544         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2545         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2547         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2551         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2552         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2553         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2554         CLOSE_WAIT                                                         TCP    127.0.0.1:9081         127.0.0.1:2557         CLOSE_WAIT   
  • #6 18305585
    DDoS132
    Level 8  
    You had to click enter to start the loop haha. It's so simple it's hard to find ...
ADVERTISEMENT