Search Unity

Can't connect to a server using TCP.

Discussion in 'Multiplayer' started by Xwilarg, Jul 20, 2017.

  1. Xwilarg

    Xwilarg

    Joined:
    Jul 13, 2016
    Posts:
    21
    Hi,
    I made a client and a server communicating with TCP socket.
    I can connect on it on my computer using my local IP (192.168.1.19) without any problem, but the others people can't access to it (even if we are on the same internet connection).
    Here's the code I'm using for connecting the client:
    Code (CSharp):
    1. try
    2.         {
    3.             socket = new TcpClient(host, port);
    4.             stream = socket.GetStream();
    5.             writer = new StreamWriter(stream);
    6.             reader = new StreamReader(stream);
    7.             isConnected = true;
    8.             connectionStatusText.color = Color.green;
    9.             connectionStatusText.text = "Connected to the server";
    10.         }
    11.         catch (SocketException)
    12.         {
    13.             isConnected = false;
    14.             connectionStatusText.color = Color.red;
    15.             connectionStatusText.text = "Not connected to the server";
    16.         }
    Does someone please know why ?

    Thanks in advance.
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    https://sv.wikipedia.org/wiki/Network_Address_Translation That might be an issue.
     
  3. Xwilarg

    Xwilarg

    Joined:
    Jul 13, 2016
    Posts:
    21
    Wouldn't it be a problem only if someone was trying to connect using my remote ip ?
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    You need external IP. People can't connect to you via local IP address.
    If you have router that blocks ports -> do a port forwarding. There's plenty of tutorials in the internet how to do that.
     
  5. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Software firewall on your server computer could be preventing connections from other computers on your local network.
     
  7. Xwilarg

    Xwilarg

    Joined:
    Jul 13, 2016
    Posts:
    21
    Sorry, I found the solution and I forgot to say it.
    As Joe-Censored said, it was only a problem of firewall.....