- Home /
Using MLAPI to network across multiple computers
So I've recently been working with MLAPI networking to just get a very simple game working before I do anything complicated. Pretty much following the SRCoder tutorial on Youtube, I have a button that lets you join as a host or a client, and then it spawns in a player prefab. However, I'm trying to connect to the host's server from another computer. I have a second computer in my house, and I was able to do it through that, but my friend who is working on the project through Unity Collaboration was unable to connect from his place. The method I have in which the computers connect is by simply typing in the host's IP address into an input field, which then sets the IP in the U Net Transport script. Does anyone know what needs to be done in order to connect to a host who is not under the same wifi? Much thanks to anyone who can help!
Answer by MenimalsEntertainment · Apr 14, 2021 at 04:40 PM
Ok so I did some research, and basically what you have to do is port forwarding on your router. Unfortunately, this is not a solution to multiplayer games and also has some risk, so I have decided to stop using MLAPI and instead use Photon for a public server, which is working well so far.
Answer by Aatifahmad · Jun 03, 2021 at 08:38 AM
Hey how did you manage to connect from another computer using same wifi? could you tell me?
Lan connection uses sockets, either TCP or UDP sockets, depending on the application you're making. I made a plugin you can just drag into your Plugins folder in your Unity project, that allows you to send and receive data from two devices on the same network, using TCP. You can find the github repo here: Lan Networking with an example file, and the plugin you can drag into your project files. @Aatifahmad
Have you check it in unity? i dont know where to put these scripts. Is it working in Mlapi?
My repo contains wrapper classes for TCP sockets, that help you to get a server and connect clients much faster, than having to worry about the extra details. If you want to use the plugin, I'll be more than happy to create some Unity scripts to get a simple application up and running for you. Otherwise, have a look at the more popular plugins, such as Mirror or Photon, which also support LAN connection.
Yes it works in Unity. In the repository, there's a folder called plugins. Create a new folder in your assets folder called Plugins, and drag the .dll file from the folder that says Net Core 2.0
into the Plugins folder. You should now have access to the namespace Networking.TCP
in your Unity scripts
Drag in the example code for the Chat App, into a Unity script, and replace static void Main
with void Start
, and replace class Program
with public class MyBehaviour : MonoBehaviour
. Also Console.WriteLine() doesn't work in Unity, so you'll have to change those to key presses or button methods.
This was the tutorial I used: https://www.youtube.com/playlist?list=PLbxeTux6kwSAseRmJeCyvkANHsI16PoM6
I found it very helpful when I was using MLAPI and I believe part 7 discusses how to connect over a local network. Obviously you don't have to follow the whole thing step-by-step, I think I skipped over part in order to see how to connect via LAN. There are also a number of other tutorials out there, but I found this one the most helpful for me. Hope this helps!
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Multiplayer server choosing requirements VPS is this enough? 0 Answers
Player sets up server UNet. 0 Answers