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 broesby · Dec 17, 2013 at 01:38 AM · networkingnetworknetwork.connect

Problem with basic networking...

I am new to networking in Unity and therefore tried this basic code from a Youtube tutorial. It works like a charm locally with two instances on the same computer. But as soon as I try online with 2 instances on 2 different computers (I even tried from my android phone as well), I get no reaction from the script.

The IP in the script is my external IP. Locally it works... as well as 127.0.0.1 ofc!

I think my problems has to do with the port (here I chose 25001). I tried a few different ones.

I also tried port forwarding on my router - opening port 25001 UDP (and TCP) to traffic.

Absolutely nothing works :-(

Now I don't know how to continue - this was my entry point as I'm not much of a coder and kinda learn as I go along.

Here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
 
     public string IP = "212.45.114.171";
     public int Port = 25001;
 
     void OnGUI()
     {
         if (Network.peerType == NetworkPeerType.Disconnected)
         {
             if(GUI.Button(new Rect(100,100,200,50),"Start Client"))
             {
                 Network.Connect(IP,Port);
             }
             if(GUI.Button(new Rect(100,150,200,50),"Start Server"))
             {
                 Network.InitializeServer(10,Port);
             }
         }
         else {
             if(Network.peerType == NetworkPeerType.Client)
             {
                 GUI.Label(new Rect(100,100,200,50),"Client");
 
                 if(GUI.Button(new Rect(100,150,200,50),"Logout"))
                 {
                     Network.Disconnect(250);
                 }
             }
             if(Network.peerType == NetworkPeerType.Server)
             {
                 GUI.Label(new Rect(100,100,200,50),"Server");
                 GUI.Label(new Rect(100,150,200,50),"Connections: " + Network.connections.Length);
 
                 if(GUI.Button(new Rect(100,200,200,50),"Logout"))
                 {
                     Network.Disconnect(250);
                 }
             }
         }
     }
 }
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 OP_toss · Dec 17, 2013 at 01:59 AM 0
Share

Is your firewall(s) off?

avatar image broesby · Dec 17, 2013 at 09:46 AM 0
Share

Yeah :-( But seems to me that Unity networking puts the running applications in Firewalls exception list by default??

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xandermacleod · Dec 17, 2013 at 09:53 AM

sounds like you oughta try using the master server to find the correct IP rather than hard-coding it. I generally find it's a bit safer.

http://docs.unity3d.com/Documentation/Components/net-MasterServer.html

First make sure your server uses the function RegisterHost()

then have the client query the master server for available server's and pick up the IP from it that way.

(In theory your code is fine, but in my limited networking ventures, the master server has been more reliable for me for this kind of issue, though im still not sure why).

Comment
Add comment · 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

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

19 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

Related Questions

Networking two separate PCs on the network 1 Answer

Network ipAddress always 0.0.0.0 on PC, correct everywhere else. 3 Answers

Why is the Network.Connect does not work with "hostdata" 0 Answers

OnConnectedToServer called multiple times 1 Answer

Implementing a news feed into my application 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