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 question was closed Dec 04, 2014 at 04:57 AM by Prasanna for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Prasanna · Jul 18, 2014 at 02:05 PM · c#rpcnetworkviewchat

Problem with Network Connection

Hello there, i have created chat system. Its working only one system, if i use that file into another system, its not working. Here is the code snippet for network connection.

 using UnityEngine;
 using System.Collections;
 
 public class Network_View : MonoBehaviour 
 {
     public string Connection_IP    = "127.0.0.1";
     public int Port_Number        = 8;
 
     public static bool Connected{ get; private set;}
 
     private void OnConnectedToServer()
     {
         Connected = true;
     }
 
     private void OnServerInitialized()
     {
         Connected = true;
     }
 
     private void OnDisconnectedFromServer()
     {
         Connected = false;
     }
 
     private void OnGUI()
     {
         if(!Connected)
         {
             Connection_IP = GUILayout.TextField(Connection_IP);
             int.TryParse(GUILayout.TextField(Port_Number.ToString()), out Port_Number);
 
             if(GUILayout.Button ("Connect"))
                 Network.Connect (Connection_IP, Port_Number);
             if(GUILayout.Button ("Host"))
                 Network.InitializeServer (5, Port_Number, true);
         }
         else
         {
             GUILayout.Label ("Connections: " + Network.connections.Length.ToString());
         }
     }
 }

-Prasanna

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 HarshadK · Jul 18, 2014 at 02:29 PM 0
Share

Do you have localhost (127.0.0.1) set-up on the machine you are trying to run this script on?

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Xtro · Jul 18, 2014 at 03:19 PM

For network enabled systems (say Multiplayer Games or Chat apps) you need a server. The IP you are connecting(from the client app) must belong to a server. A server serves all the clients as a hub. When you want to send an information or command to another client, you must send it via the server.

Some advanced multiplayer games(like starcraft) can be played via connecting each player to each other directly without a server but still the players will need a server to find other players.

For example the games like WOW can't be played without a server. All the information goes to server and comes from server including the chat.

Your code is working on your own computer because the both clients are connecting to the same IP which is your computer's local IP (127.0.0.1) This setup can't run on internet or on local network.

You should have a dedicated server computer for your application. This server will run a server version of your app. It's task is to transfer the chat data between client. Each client must run on different computers and they all have to connect to the server via server's real IP (not 127.0.0.1)

As a summary:

1) Write a server app : waiting for client connections and passes the chat data between clients.

2) Write a client app : connecting to server via it's real IP (you can get server's real ip from its network settings)

3) run the server app on a dedicated computer.

4) run the client apps on separate computer.

P.S. : Ofcourse it's possible to run the clients and the server on the same computer. I'm just explaining the fundamentals of networking here.

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 Prasanna · Jul 18, 2014 at 03:52 PM 0
Share

So thanks for your help, i really appreciate it. Where can i learn about to create real Ip address. Any link must be appreciated.

-Prasanna

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

Multiple Cars not working 1 Answer

Network Chat not sending messages to other clients 1 Answer

RPC not being called 1 Answer

Clearing RPC buffer on a NetworkView 0 Answers

Unity crashes when doing an RPC. 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