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 gamezdragon · Oct 05, 2013 at 06:02 PM · networkhowaddress

When Networking do you need to use your IP address?

Just as the title says. I know the answer may seem obvious or that, yes, everyone has to use their IP address, but I followed a certain tutorial. Everything has worked well so far, but when I put in my IP address for the ipAddress variable, and try to connect or start a server on the game, it freezes or says that the server cannot connect.

Here is the code:

 var ipAddress : String = "127.0.0.1";
 var port : int = 25167;
 var maxConnections : int = 10;
 
 var playerGO : GameObject;
 
 var log : String = "";
 var myMessage : String = "";
 var chatting : boolean = false;
 
 function OnGUI () {
     if (Network.peerType == NetworkPeerType.Disconnected) {
         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")) {
             for (var l : GameObject in FindObjectsOfType (GameObject)) {
                 l.BroadcastMessage ("OnLoadNetworkLevel", SendMessageOptions.DontRequireReceiver);
             }
             print ("Connecting . . .");
             Network.Connect (ipAddress, port);
         }
         
             if (GUILayout.Button ("START SERVER")) {
                 for (var l : GameObject in FindObjectsOfType (GameObject)) {
                 l.BroadcastMessage ("OnLoadNetworkLevel", SendMessageOptions.DontRequireReceiver);
             }
             print ("Starting Server . . .");
             Network.InitializeServer (maxConnections, port);
         }
     }
     else {
         if (GUILayout.Button ("DISCONNECT")) {
             Network.Disconnect (200);
         }
         if (Input.GetKeyDown (KeyCode.T)) {
             chatting = true;
         }
         if (Input.GetKeyDown (KeyCode.Escape)) {
             chatting = false;
         }
         if (chatting) {
             GUILayout.Label (log);
             myMessage = GUILayout.TextField (myMessage);
             if (GUILayout.Button ("SEND MESSAGE")) {
                 networkView.RPC ("Chat", RPCMode.All, myMessage);
             }
         }
     }
 }
 
 function OnConnectedToServer () {
     print ("Connected!");
     OnLoadNetworkLevel ();
 }
 
 function OnPlayerDisconnected (player : NetworkPlayer) {
     Network.RemoveRPCs (player);
     Network.DestroyPlayerObjects (player);
 }
 
 function OnDisconnectedFromServer () {
     Application.LoadLevel (Application.loadedLevel);
 }
 
 function OnLoadNetworkLevel () {
     yield 25;
     GetComponent (Camera).rect = Rect (0.7, 0.7, 0.25, 0.25);
     GetComponent (GUILayer).enabled = false;
     if (Network.peerType != NetworkPeerType.Disconnected) {
         Network.Instantiate (playerGO, transform.position, transform.rotation, 0);
     }
 }
 
 @RPC
 function Chat (input : String) {
     log += "\n";
     log += input;
 }

So do I need to use MY IP address? Or is there a more simple answer? Since currently my IP address isn't working for the networking.

Comment
Add comment · Show 2
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 tw1st3d · Oct 05, 2013 at 06:23 PM 0
Share

It can't be just the IP address that's giving you a problem. Connecting to 127.0.0.1 will always connect as long as there are no program$$anonymous$$g errors, even if ports aren't open. $$anonymous$$ake sure you don't have any other mistakes that could cause it to not go through.

avatar image gamezdragon · Oct 05, 2013 at 06:25 PM 0
Share

I think I've found my problem. The server works, and I found out why I couldn't connect. I can start the server, chat, and everything, but the screen is blank. I see no map that I've created, my character, nothing.

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

How to pass variables in a Network using RPC function(s) 0 Answers

How to set the player number in a network game? 1 Answer

Calling System.Net.Dns.GetHostEntry(sHostName) failed 0 Answers

How to get the mac address of a remote IP on the LAN? 0 Answers

Networking ? 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