- Home /
Can create and play on a server, but not join one.
I am making a 2D multiplayer game and am having a lot of issues, the biggest one being that you are unable to join a server. If you create a server you can control your character and move around, but you cannot even connect to someone else's server, the button to do so just does nothing
When joining someone else's server this is the error message:
Failed to connect to xx.xxx.xxx.xx:50005 because this system is already connected. This can occur when the network connection is disconnected too quickly for the remote system to receive the disconnect notification, for example when using Network.Disconnect(0).
When someone tries to join your server this is the error message:
Receiving NAT punchthrough attempt from target 234187376866924072 failed
here is my NetworkManager script:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
private const string typeName = "Jellow's 2D Maze Shooter";
private const string gameName = "GameName";
public GameObject redPrefab;
private void StartServer()
{
Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName);
}
void OnServerInitialized() {
SpawnRed();
}
void OnGUI()
{
if (!Network.isClient && !Network.isServer) {
if (GUI.Button (new Rect (100, 100, 250, 100), "Start Server"))
StartServer ();
if (GUI.Button (new Rect (100, 250, 250, 100), "Refresh Hosts"))
RefreshHostList ();
if (hostList != null) {
for (int i = 0; i < hostList.Length; i++) {
if (GUI.Button (new Rect (400, 100 + (110 * i), 300, 100), hostList [i].gameName))
JoinServer (hostList [i]);
}
}
} else if (GUI.Button (new Rect (100,100,250,100), "Disconnect"))
Network.Disconnect();
}
private HostData[] hostList;
private void RefreshHostList()
{
MasterServer.RequestHostList(typeName);
}
void OnMasterServerEvent(MasterServerEvent msEvent)
{
if (msEvent == MasterServerEvent.HostListReceived)
hostList = MasterServer.PollHostList();
}
private void JoinServer(HostData hostData)
{
Network.Connect(hostData);
}
void OnConnectedToServer()
{
SpawnRed();
}
private void SpawnRed() {
Network.Instantiate(redPrefab, new Vector3(0f, 5f, 0f), Quaternion.identity, 0);
}
}
Edit: Sorry for bump but I can't find an answer for this anywhere and really need some help with this. :)
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Tanks!!! online question 2 Answers
Question about UNET 0 Answers
Unity Online Not Work 2 Answers
attached prefabs before client joins 2 Answers