Search Unity

SocketException: Connection Refused - but can connect with other programs

Discussion in 'Scripting' started by Jelling, Jan 11, 2021.

  1. Jelling

    Jelling

    Joined:
    Jan 27, 2013
    Posts:
    6
    I have a Unity script that connects to a TCP port. When it is connecting to localhost, it works, but when connecting to a remote ip on the local network it receives "SocketException: Connection Refused" as an error.

    Typically, the cause of this is a firewall rule on the host or the client. But I ruled this out by running a curl to the port on the remote host and it works. I also verified this by running WireShark and capturing the exchanged network packets.

    Any ideas? I am running Unity 2019.4.17f1 Personal on MacOS.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Sounds like software firewall settings on the computer acting as the host.
     
  3. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    In MacOS - at least when creating a sandboxed Application with XCode - you need to set up the correct entitlements for your app in your plist (I think it's something like com.apple.security.network.client)

    I have no idea how unity handles that but looking at the macOS specific settings may help (if Unity's apps aren't sandboxed, this probably does not apply).
     
  4. Jelling

    Jelling

    Joined:
    Jan 27, 2013
    Posts:
    6
    I figured it out. The external IP was being over-written by another component so it was trying to connect to localhost which was incorrect. Thank you all the same for the help.