Unity Network Connection Does Not Work

Asked 2 years ago, Updated 2 years ago, 45 views

Unity cannot use its unique networking system to connect to its own server from other clients.
Currently, there are no errors when playing with the Unity editor, and when connecting locally, the Unity editor and the application built for Windows will be able to synchronize the data well.However, when I try to connect to a network using an IP address from an Android or Windows app, I cannot connect to my server.
Perhaps the problem is that the IP address is not obtained well, but the IP address should be correct because I use my own IP address, which I checked from several IP address verification sites.
Is there any other problem with Unity's network connection?

The following script is used to obtain an IP address:

Development Environment ·OS Windows 10
·Unity 5.6.1f
· VR Application Development with Unity

using System.Collections;
using System.Collections.General;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.VR;

public class NetworkStart:NetworkBehavior {
    public GameObject DiveCamera;
    public string hostIP="xxx.xx.xx.xxx";

    void Awake() {
        VRSettings.enabled = false; 

        # if (UNITY_ANDROID||UNITY_IPHONE)
        DiveCamera.SetActive(true);
        NetworkManager net=GetComponent<NetworkManager>();
        net.networkAddress=hostIP;
        net.StartClient();
        # else
        DiveCamera.SetActive(false);
        #endif
    }
}

unity3d

2022-09-30 14:34

1 Answers

As for the continuation of the comment, I will write it here as an answer.

I asked if it works on the same PC because I suspected that it might not be able to communicate with other PCs or terminals.

I imagine that the first communication will be from the client to the server, but I think it would be good to check if the PC on the server side is blocking communication from the outside.For example, disabling the firewall on that PC might enable communication.

If you disable the firewall, you will be able to communicate, you will need to open the port that the app uses in the firewall settings on the server side.


2022-09-30 14:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.