Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Connect to Unity from external program

Discussion in 'Scripting' started by HaggiKrey, May 16, 2018.

  1. HaggiKrey

    HaggiKrey

    Joined:
    Apr 19, 2018
    Posts:
    10
    Hi,
    I try to connect to unity from an external program via UDP. I found a great NetworkTransport example in the docs and it works fine if I communicate between two Unity instances. But as soon as I try to connect from another non-Unity program, I get either a warning: "Warning: wrong connectionId in received user packet" or nothing at all if I try it from python like this:

    Code (csharp):
    1. UDP_IP = '127.0.0.1'
    2. UDP_PORT = 1531
    3. MESSAGE = "Hello, World!"
    4.  
    5. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    6. sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    What works fine if I have a server and client implemented in python, but I simply do not get any response in Unity. So I suppose my understanding of the way the NetworkTransport works is wrong.
    Is it designed to work with any UDP communication, or does it only work inside a Unity Network?
     
  2. HaggiKrey

    HaggiKrey

    Joined:
    Apr 19, 2018
    Posts:
    10
    Just in case anyone is interested: I was unable to make it work with builtin NetworkTransport classes. So I implemented the System.Net.Sockets with UdpClient and now it works like a charm.
     
  3. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    44
    We're using TcpClient in Unity to connect to our p2p servers written in Go. This means that Unity is only burdened with a vanilla tcp connection while our Go nodes do all the heavy lifting (wrt to p2p data sharing and replicating). This also means we get full platform support since our Unity client app can run on Windows, macOS, linux, *and* iOS & Android. Our iOS and Android client, just like the desktop clients, connect to our server via tcp (TcpClient), but for the mobile platforms, the server they're connected to is remote.
     
    Last edited: Jul 1, 2018