Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity web server

Discussion in 'Multiplayer' started by WintersunIsHere, Jan 19, 2020.

  1. WintersunIsHere

    WintersunIsHere

    Joined:
    Jan 19, 2020
    Posts:
    2
    Hello there,
    Is there any way to unity host a server and respond to urls?

    I'm going to describe why it's needed if any other solution you guys may have would be appreciated.
    We're gonna have a real robot soon in our lab, specifically a rover, which is gonna be controlled through some endpoints provided by the designer and wifi network we connect to, and has depth and other sensors which all the data can be retrieved through the endpoints.
    As we're gonna implement and test different algorithms for the robot to move over the area, the best way before rover was gonna get ready is to use a simulated environment. So what's better than unity? Therefore we need unity to respond to request through urls like /move, /rotate etc.
    We have lot of experience in Unity, and every other major web related stuff and I know there's workaround using websockets but actually the architecture with sockets seems weird and it's not gonna be used later when the real robot comes.

    So any help would be much appreciated.
     
    Last edited: Jan 19, 2020
  2. drawcode

    drawcode

    Joined:
    Jul 21, 2008
    Posts:
    72
    There are some assets that have internal web servers:

    https://assetstore.unity.com/packages/tools/network/web-server-for-unity-126120
    https://assetstore.unity.com/packages/tools/network/http-142078

    Hosting a web server would require an OS on the robot that has networking, DNS, wifi and can host a web server. Seems like you'd want to just run it in another language like js/node, python or .NET Core etc rather than Unity. Any of those you can build a simple web server in but the IP/DNS resolution would be on the local network.

    You could still control it from a server if you had it update data on the server that it polled or looked at. If you do have a local web server outside the Unity app the Unity app could look for data changed locally by the web server. If there isn't any visual need or a UI needed, it would be better to build the web server part in others like just C# in .NET Core or the others I mentioned.

    Something like HttpListener in C# could be setup for easy mini web server that is very basic: https://stackoverflow.com/questions/769156/http-library-in-c-sharp

    If you can have a server you just give it a unique UUID/GUID and have it hit the server or join a room like a WebRTC or socket channel, they you can send commands to it.

    You could have Unity app on the robot respond by polling a server for state changes i.e. on a server.

    Or when you hit a certain url like /move it can make an RPC call or sockets call using WebRTC.
    https://github.com/Unity-Technologies/com.unity.webrtc

    Or use websockets directly.
     
    Last edited: Jan 19, 2020
  3. WintersunIsHere

    WintersunIsHere

    Joined:
    Jan 19, 2020
    Posts:
    2
    Hello and Thanks for the quick response

    Actually robot will not have unity3D on it. the robot will be controlled with some endpoints given to us I think it's gonna be written in c++ or something dunno yet. the requests will be sent by us to the robot, I'm planning to do it with python to send commands and receive data to and from the robot but the robot is getting built currently as I'm writing this message and it will not be ready in like another 30 days or sth. As we're gonna do some tests I wanted to have a simulated robot. The best thing I could think of was unity3d. but as the robot is hosting it's own server and we are gonna send commands through roughly a REST api I wanted to do the same thing in unity3d.

    The Final architecture is something like this:

    Robot(API) <----> Laptop
    so endpoints like /move , /rotate will be get or post requests to the robot.

    Right now The for the simulated env I want sth like this:

    Unity3d(API) <-----> Laptop
    so endpoints on the server should be on hosted on unity3d and /move and /rotate will move the robot 3d object and rotate inside unity3d scene, so we can see if we're doing something wrong or not.
     
  4. unity_VqDLCqvhyul-tQ

    unity_VqDLCqvhyul-tQ

    Joined:
    Feb 4, 2020
    Posts:
    1
    hello i find your project quite similar to mine.
    I am designing an autonomous robot and i would like to have it simulated in a unity scene. I first would like to just be able to send simple data from robot to unity. What is the solution u selected please ? i find it also quite difficult to aprehend networking bassics in unity
    thanks a lot.