Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by Meral · Feb 07, 2015 at 10:47 AM · networkingmultiplayerserverconnection

Multiplayer not working

Hi I am trying to set up a multiplayer game. So i followed a tutorial (http://cgcookie.com/unity/2011/12/20/introduction-to-networking-in-unity/) and made a first test. Now i can connect with myself and it works just fine, but when my friend tries to connect, things get weird. Usually one player starts a server, and the other clicks the refresh hosts button. Then a button appears for each available host/server. When i test it on my own, i can connect by clicking on this new button. When my frined tries it however, nothing happens. The same situation when he hosts and i try to connect.

This is the full Network Script:

 #pragma strict
 
 var gameName : String = "TestMultiplayerGame123321";
 private var refreshing : boolean;
 private var hostData : HostData[];
 
 var Button01 : GameObject;
 var Button02 : GameObject;
 
 var player : GameObject;
 var spawn : GameObject;
 
 //Start Server
 function StartServer()
 {
     Network.InitializeServer(2, 25000, !Network.HavePublicAddress);
     MasterServer.RegisterHost(gameName, "Test", "This is a test");
 }
 
 //Messages
 function OnServerInitialized()
 {
     Debug.Log("Server Initialized");
     spawnPlayer();
 }
 
 function OnConnectedToServer()
 {
     spawnPlayer();
 }
 
 //Spawning a Player
 function spawnPlayer()
 {
     Network.Instantiate(player, spawn.transform.position, Quaternion.identity, 0);
 }
 
 function OnMasterServerEvent(mse : MasterServerEvent)
 {
     if (mse == MasterServerEvent.RegistrationSucceeded)
     {
         Debug.Log("Registration Succeeded");
     }
 }
 
 //Refreshing Hosts etc. 
 function RefreshHostList()
 {
     MasterServer.RequestHostList(gameName);
     refreshing = true;
 }
 
 function Update()
 {
     if (refreshing)
     {
         if(MasterServer.PollHostList().Length > 0)
         {
             refreshing = false;
             Debug.Log(MasterServer.PollHostList().Length);
             hostData = MasterServer.PollHostList();
             //ListHosts();
         }
     }
 }
 
 function OnGUI()
 {
     if (!Network.isClient && !Network.isServer)
     {
         if (hostData != null)
         {
             for (var i : int = 0; i < hostData.length; i++)
             {
                 if(GUI.Button(Rect(Screen.width * 0.5, Screen.height * 0.1 + i/2, 50, 50), hostData[i].gameName))
                 {
                     Network.Connect(hostData[i]);
                 }
             }
         }
     }
     else
     {
         Button01.active = false;
         Button02.active = false;
     }
 }

Can anyone help me?

Thanks in advance :-)

Btw, don´t let the usage of both the new GUI system and the old one confuse you. I was experiencing some problems so i alternated between both for test purposes

Comment
Add comment · Show 6
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
avatar image valaxgames · Feb 07, 2015 at 11:25 AM 1
Share

Try portforwarding the port 25000.

avatar image Meral · Feb 07, 2015 at 11:27 AM 0
Share

Thanks for the quick answer :-). What do you mean? What would portforwarding mean?

avatar image valaxgames · Feb 07, 2015 at 11:30 AM 1
Share

By default, your router will block connections that go through a certain internet 'port'. It's like a gate for internet traffic.

Find your route on the guide and follow the instructions. Port forwarding guide

If you need help pm me :)

avatar image Meral · Feb 07, 2015 at 11:32 AM 0
Share

Would Hamachi work ins$$anonymous$$d?

avatar image valaxgames · Feb 07, 2015 at 11:55 AM 1
Share

Don't see why it wouldn't.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Noob_Vulcan · Feb 07, 2015 at 12:15 PM

Since you are using Unity Master Server ,there is possibility that it is down(its a test server). So rather can connecting via Master Server connect directly via IP addresses

 private void StartServer ()
         {
                 Network.InitializeServer (1, 25003, true);
                 MasterServer.RegisterHost (_typeName, _gameName);
                 Debug.Log ("My Ip " + Network.player.ipAddress);
         }
     
 
     #region ClickEvents
 
         public void OnClick_StartServer ()
         {
 
                 if (!Network.isServer && !Network.isClient)
                         StartServer ();
                 else
                         Debug.Log ("Server Running...");
         }
 
         public void OnClick_ConnectServer ()
         {
 
                 Network.Connect (_serverPcIpAddress, 25003);
 
         }
 
     #endregion


You can get Your IP address via Network.player.ipAddress . Just ask your friend to connect to this address.

For now, you will have to hard code ServerPCAddress.

Hope this helps :)

Comment
Add comment · Show 3 · Share
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
avatar image Meral · Feb 07, 2015 at 04:08 PM 0
Share

Thanks for the answer. Still doesn´t work unfortunately :-(.

avatar image Noob_Vulcan · Feb 07, 2015 at 04:10 PM 0
Share

@$$anonymous$$eral : can u post ur whole code ..what u did

avatar image Meral · Feb 08, 2015 at 01:00 PM 0
Share

The code at the top is everything already

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.

Follow this Question

Answers Answers and Comments

21 People are following this question.

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

Related Questions

Unity networking tutorial? 6 Answers

Multiplayer game in webplayer not working on server 1 Answer

Why can't the client move a networked object ? 1 Answer

Popular Multiplayer Framework/Services? 0 Answers

Making own server instead of using unity matchmaking and relay servers? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges