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 /
avatar image
0
Question by Alexvaldes0612 · Jul 03, 2013 at 01:16 AM · multiplayernetworkserver

Players can't connect to my server

So I coded this multiplayer game and when i checked with my self it worked, but i gave my friend my public ip and port so he can join and he couldn't. I port forwarded my port.

this is my NetworkManager code

 #pragma strict
 
 //ADDED FOR CROSSHAIR
 var crosshairTexture : Texture2D;
 var position : Rect;
 static var OriginalOn = true;
 //
 
 var playerPrefab : GameObject;
 var spawnObject : Transform;
 
 //ADDED FOR ONLINE
 var ipAddress : String = "127.0.0.1";
 var port : int = 25565;
 var maxConnections : int = 6;
 //
 
 var gameName : String = "level1";
 private var refreshing : boolean = false;
 private var hostData : HostData[];
 
 function OnGUI () {
 
 if(!Network.isClient && !Network.isServer) {
 //ADDED FOR ONLINE
     GUILayout.BeginHorizontal ();
     ipAddress = GUILayout.TextField (ipAddress);
     GUILayout.Label ("IP ADDRESS");
     GUILayout.EndHorizontal ();
     
     GUILayout.BeginHorizontal ();
     var tempPort : String;
     tempPort = GUILayout.TextField (port.ToString());
     port = parseInt(tempPort);
     GUILayout.Label ("PORT");
     GUILayout.EndHorizontal();
     
     if(GUILayout.Button ("CONNECT")) {
         print("Connecting...");
         Network.Connect (ipAddress, port);
         showCrosshair(); //ADDED
     }
 //
  if (GUI.Button(Rect(Screen.width/2,Screen.height/2,100,20),"Start Server")) {
         startServer();
         showCrosshair(); //ADDED
 }
 
  if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 30,100,20),"Refresh Hosts")) {
         Debug.Log("Refresh");
         refreshHostList();
 }
     if(hostData) {
 
     for(var i:int = 0; i<hostData.length; i++) {
     
     if(GUI.Button(Rect(Screen.width/2,Screen.height/2 + 60,100,20),hostData[i].gameName)) {
         Network.Connect(hostData[i]);
     
     
     }
     
     
 }
 }
 }
 // ADDED FOR CROSSHAIR
     if(OriginalOn == true)
     {
         GUI.DrawTexture(position, crosshairTexture);
     }
 //
 }
 
 
 function Update () {
 
     if(refreshing) {
         if(MasterServer.PollHostList().Length > 0) {        
         refreshing = false;
         Debug.Log(MasterServer.PollHostList().Length);
         hostData = MasterServer.PollHostList();
         
         
         }
     
     
     }
 
 
 
 }
 
 
 function startServer () {
     // Stuff in green in for LAN not ONLINE
     //Network.InitializeServer(32,25001, !Network.HavePublicAddress);
     Network.InitializeServer (maxConnections, port, false);
     //MasterServer.RegisterHost(gameName, "Test 1", "This is a testing room");
     
 }
     
     
     
 function OnServerInitialized () {
 
     Debug.Log("server initialized");
     spawnPlayer();
     
     
 }
 
 function OnConnectedToServer () {
 
     spawnPlayer();
 
 
 }
 
 function spawnPlayer () {
 
     Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
 
 }
 
 function OnMasterServerEvent(mse:MasterServerEvent) {
 
     if(mse == MasterServerEvent.RegistrationSucceeded) {
     Debug.Log("Registered Server");
     
     }
     
 }
     
     
 function refreshHostList () {
 
     MasterServer.RequestHostList(gameName);
     refreshing = true;
 }
 
 //ADDED FOR CROSSHAIR
 function showCrosshair () {
     position = Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height - 
         crosshairTexture.height) /2, crosshairTexture.width, crosshairTexture.height);
 }
 //

Please help, thank you

Comment
Add comment · Show 1
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 Benproductions1 · Jul 03, 2013 at 03:06 AM 0
Share

Have you tried connecting using the Unity $$anonymous$$aster Server? Because if that doesn't work, then it's not a problem with your game

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Unity networking tutorial? 6 Answers

Networking??? 2 Answers

Networked multiplayer with dedicated server 0 Answers

Can you create a Stand alone server for your game? 0 Answers

can i use unity and php to develop a multi player game 2 Answers


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