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 HarrisonGPink · Apr 04, 2014 at 07:56 AM · networkingnetworknetwork.connect

Networking two separate PCs on the network

Hi all, I'm very very new to coding, and I've been trying to learn some super simple Networking stuff. I've been following this tutorial: http://www.palladiumgames.net/tutorials/unity-networking-tutorial/

which has been very helpful. Sadly, when I try to load a Client on my laptop and the Server on my desktop, it doesn't work. I've gotten down to completing the first script (before creating a cube). I simply wanted to see if I could establish a connection between two separate computers on the same network.

I didn't leave the connectionIp variable as 127.0.0.1. I changed it to the local IP of my desktop (192.168.1.2).

Opening two windows on the laptop and starting one as a server and one as a client connects properly even though the connectionIP variable isn't set to local, and that machine's IP is (192.168.1.6).

Here's the script:

 public string connectionIP = "192.168.1.2";
     public int connectionPort = 25001;
     
     void OnGUI()
     {
         if (Network.peerType == NetworkPeerType.Disconnected)
         {
             GUI.Label(new Rect(10, 10, 200, 20), "Status: Disconnected");
             if (GUI.Button (new Rect(10, 30, 200, 20), "Connect Client"))
             {
                 Network.Connect(connectionIP, connectionPort);
             }
             if (GUI.Button (new Rect(10, 50, 120, 20), "Initialize Server"))
             {
                 Network.InitializeServer(32, connectionPort, false);
             }
         }
         else if (Network.peerType == NetworkPeerType.Client)
         {
             GUI.Label (new Rect(10, 10, 300, 20), "Status: Connected as Client");
             if (GUI.Button (new Rect(10, 30, 120, 20), "Disconnect"))
             {
                 Network.Disconnect(200);
             }
         }
         else if (Network.peerType == NetworkPeerType.Server)
         {
             GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as Server");
             if (GUI.Button(new Rect(10, 30, 120, 20), "Disconnect"))
             {
                 Network.Disconnect(200);
             }
         }
     }

What am I missing? What don't I understand yet?

Thanks!

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 Fappp · Apr 04, 2014 at 08:54 AM 0
Share

Try using the unity master server, it makes it really easy to do networking:

Docs

avatar image HarrisonGPink · Apr 05, 2014 at 05:55 AM 0
Share

I'll look into it, but for the sake of learning, can anyone help me understand what is going wrong with my code?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Apr 05, 2014 at 06:38 AM

Well, that doesn't make much sense ;) You said if you run s server and a client on your laptop it works. In this case, when you in fact are using "192.168.1.2" as IP, your laptop has that IP address and not your desktop. Have you simply tried to reverse your test? Start the server on the laptop and run the client on the desktop? If it works your IP addresses are the other way round.

Also what you should check is to what value is connectionIP set in the inspector. Since connectionIP is public, Unity will serialize the value so the field-initializer value in the script becomes useless. Maybe you changed it in the inspector or it was a different IP when you added the script / variable for the first time.

Comment
Add comment · Show 1 · 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 HarrisonGPink · Apr 05, 2014 at 06:48 AM 0
Share

The second part was the solution. I had to edit the public value in the inspector. Thank you!

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

22 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 avatar image

Related Questions

Problem with basic networking... 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

LLAPI How to receive the HostId on the client? 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