• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by novavr · Apr 20, 2017 at 06:28 PM · c#networkingphotonserver

Problems with Photon self-hosted server

So I am trying to set up a self-hosted server for a project I am doing. Currently I have the settings in the Unity inspector as set to self-hosted, the server IP is set to my local IP and the port is set to 5055, the Appid is entered,and the RunInBackGround checkbox is checked as well as the AutoJoinLobby client setting checkbox. In the Photon Control I have the Game Server IP set to Autodetect public. On my network I have a static public IP facing toward the WAN and in my LAN I have set up a static local IP so the IP never changes for my computer on my local network or on the outside internet. I have set up the router to forward traffic from port 5055 to port 5057 all to my local IP address. (since the IP is static from the ISP the IP really lives on the router and you don't forward to a public IP but to a local one) The firewall is configured to let traffic through for those ports as well. I am using the Unity SDK version of Photon Server which has two folders that are named MasterServer and GameServer, in both of these folders I opened the Photon.LoadBalancing.dll.config files and modified the value for the MasterIPAddress so that is reads to my static public IP. In the MasterServer file this was line 147 and in the GameServer file it was line 141. Now I have a script that is attached to a gameobject in my project that persists from the start to the main scene. I am currently using the ConnectWithSettings, and the JoinOrCreateRoom. My problem is that when I load into the main scene I can tell that OnJoinRoom is not being called because i have several prefabs that are supposed to instantiate when you load into the room. Below is my code and the console from when you load into the main scene. Any help with this would be very much appreciated. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Photon; using Dissonance;

 public class Connect : Photon.PunBehaviour {
 
     public Dropdown genderDropDown;
     public InputField roomName;
 
     private string room;
     private int playerCount = 0;
     private PhotonView masterView;
     private string _textMessage = "";
     private readonly List<string> _textLog = new List<string>();
     private int _count;
     private RoomOptions roomOptions;
     private TypedLobby PGS;
 
     private string address = "NOT_SHOWING_IN_EXAMPLE";
     private int port = 5505;
     private string appID = "42aa30ee-f094-4aa1-bdd0-e74ed652592c";
     private string gameVersion = "v.1";
 
     //status indicator for connection
     // ReSharper disable once UnusedMember.Local (Justification: Used implicitly by unity)
     private void OnGUI()
     {
         GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
 
         if (PhotonNetwork.isMasterClient)
             GUILayout.Label(PhotonNetwork.connectionStateDetailed + " (Master Client)");
         else
             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
 
         if (PhotonNetwork.room != null)
             GUILayout.Label("Room: " + PhotonNetwork.room.Name);
 
         GUILayout.Label(PhotonNetwork.NetworkStatisticsToString());
 
         GUILayout.Label("Photon Players:");
         foreach (var player in PhotonNetwork.playerList)
         {
             if (player.IsLocal)
                 GUILayout.Label("> '" + player.ID + "' (Local)");
             else
                 GUILayout.Label("> '" + player.ID + "'");
         }
 
         GUILayout.Label("Dissonance Players:");
         var comms = FindObjectOfType<DissonanceComms>();
         if (comms == null)
         {
             while (comms == null)
             {
                 return;
             }
         }
         if (comms.isActiveAndEnabled)
         {
             foreach (var player in comms.Players)
             {
                 if (!player.IsConnected)
                     continue;
 
                 if (player.Name == comms.LocalPlayerName)
                     GUILayout.Label("> '" + player.Name + "' (Local)");
                 else
                     GUILayout.Label("> '" + player.Name + "' Speaking:" + player.IsSpeaking);
             }
 
             GUILayout.Space(25);
 
             GUILayout.Label("Chat: ");
             _textMessage = GUILayout.TextField(_textMessage);
             if (GUILayout.Button("Send"))
             {
                 comms.Text.Send("Global", _textMessage);
                 _textMessage = "";
             }
 
             for (int i = 0; i < Mathf.Min(10, _textLog.Count); i++)
             {
                 GUILayout.Label(_textLog[_textLog.Count - 1 - i]);
             }
         }
     }
 
     // Automatically connect to the acting server
     void Start()
     {
         //bool connectToMaster = PhotonNetwork.ConnectToMaster(address, port, appID, gameVersion);
         PhotonNetwork.networkingPeer.SentCountAllowance = 15;
         PhotonNetwork.ConnectUsingSettings("LEAVE_THIS_ALONE");
         PhotonNetwork.automaticallySyncScene = true;
         DontDestroyOnLoad(gameObject);
         Debug.Log("Connecting to server...");
         PhotonNetwork.NetworkStatisticsEnabled = true;
         //PhotonNetwork.JoinLobby(PGS);
     }
 
     //Automatic Photon Call
     public override void OnConnectedToPhoton()
     {
         Debug.Log("Connected to server");
         Debug.Log("Server IP: " + PhotonNetwork.ServerAddress);
     }
 
     public override void OnConnectionFail(DisconnectCause cause)
     {
         Debug.Log("Failed to connect to server");
         Debug.Log("Cause seems to be: " + cause);
     }
 
     //Called when either host or join button is pushed in the start scene
     public void JoinOrHostRoom()
     {
         room = roomName.text;
         if (room == "" || room == null)
         {
             room = "room1";
         }
         bool iscreated = PhotonNetwork.JoinOrCreateRoom(room,roomOptions,PGS);
         PhotonNetwork.LoadLevel("Main");
         PhotonNetwork.automaticallySyncScene = true;
         Debug.Log("Created Room");
         Debug.Log("iscreated:" + iscreated);
     }
 
     //Automatic Photon Call
     public override void OnJoinedLobby()
     {
         Debug.Log("Joined Lobby");
     }
 
     //Called when a room is created
     public override void OnCreatedRoom()
     {
         Debug.Log("Room Created: " + PhotonNetwork.room.Name);
     }
 
     //Called when a room is joined
     public override void OnJoinedRoom()
     {
         if (PhotonNetwork.room != null)
         {
             Debug.Log("Connected to room: " + PhotonNetwork.room.Name);
             playerCount += 1;
         }
         else
         {
             Debug.Log("Not in a room.");
         }
 
         Debug.Log("Player count is: " + playerCount);
 
         PlayerSpawn();
 
         var comms = FindObjectOfType<DissonanceComms>();
 
         comms.Rooms.Join("Global");
         comms.Text.MessageReceived += (msg) => { _textLog.Add(msg.Sender + " Says > " + msg.Message); };
 
 
     }
 
     //Photon Read Automatic Fallback
     public void OnPhotonRandomJoinFailed()
     {
         room = roomName.text;
         if (room == "" || room == null)
         {
             room = "room1";
         }
         Debug.Log("Failed to find room, creating host");
         PhotonNetwork.automaticallySyncScene = true;
         PhotonNetwork.CreateRoom(room);
         PhotonNetwork.LoadLevel("Main");
     }
 
     //Spawn a player prefab based on the gender selected in the dropdown
     public void PlayerSpawn()
     {
         if (genderDropDown.value == 1)
         {
             PhotonNetwork.Instantiate("MaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
             PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
             PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
         }
         if (genderDropDown.value == 2)
         {
             PhotonNetwork.Instantiate("FemaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
             PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
             PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
         }
         if (genderDropDown.value == 0)
         {
             PhotonNetwork.Instantiate("MaleVRPlayer", ViveManager.instance.head.transform.position, ViveManager.instance.head.transform.rotation, 0);
             PhotonNetwork.Instantiate("leftHand", ViveManager.instance.leftHand.transform.position, ViveManager.instance.leftHand.transform.rotation, 0);
             PhotonNetwork.Instantiate("rightHand", ViveManager.instance.rightHand.transform.position, ViveManager.instance.rightHand.transform.rotation, 0);
         }
     }
 }

alt text

console.png (102.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

(PUN) How to set up local player's position and other player's positions at a fixed transform.position? 0 Answers

Unity3D Photon movement synchronization 0 Answers

What's an acceptable network send rate? 1 Answer

How to network a large map with 4000+ movable objects using Photon Unity Networking? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges