Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Suraksha226 · Jun 22, 2018 at 11:43 AM · networkingserverclientcrossplatform

Client and server communication

I am new to unity, i want to control my Game objects over WiFi. I followed this tutorial.

I have created the 2 scenes (server and client) and have the server running through unity editor and client running on my mobile phone where both server and client are connected to the same WiFi.

The IP address varies on mobile phone and gives me a status "false". I turned off the Windows firewall, i also made sure that the port number was not occupied but nothing worked for me. Below is the client and server code. Please help me fix if i am doing a mistake.


Server end code( Which is in unity Editor)

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.NetworkSystem;
 using UnityStandardAssets.CrossPlatformInput;
 
 public class NetworkServerUI : MonoBehaviour {
 
     CrossPlatformInputManager.VirtualAxis m_HVAxis;
     CrossPlatformInputManager.VirtualAxis m_VVAxis;
     string horizontalAxisName = "Horizontal";
     string verticalAxisName = "Vertical";
     void OnGUI()
     {
         string ipaddress = Network.player.ipAddress;
         GUI.Box(new Rect(10, Screen.height - 50, 100, 50), ipaddress);
         GUI.Label(new Rect(20, Screen.height - 35, 100, 20), "Status" + NetworkServer.active);
         GUI.Label(new Rect(20, Screen.height - 20, 100, 20), "Connected" + NetworkServer.connections.Count);
     }

     void Start () {
         m_HVAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
         CrossPlatformInputManager.RegisterVirtualAxis(m_HVAxis);
         m_VVAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
         CrossPlatformInputManager.RegisterVirtualAxis(m_VVAxis);
         NetworkServer.Listen(25000);
         NetworkServer.RegisterHandler(888, ServerReceiveMessage);
     }
     private void ServerReceiveMessage(NetworkMessage message)
     {
         StringMessage msg = new StringMessage();
         msg.value = message.ReadMessage<StringMessage>().value;
 
         string[] deltas = msg.value.Split('|');
         m_HVAxis.Update(Convert.ToSingle(deltas[0]));
         m_VVAxis.Update(Convert.ToSingle(deltas[1]));
     }
 }
 


Client End code which is running on my mobile

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.NetworkSystem;
 
 
 public class NetworkClientUI : MonoBehaviour {
 
     static NetworkClient client;
 
     void OnGUI()
     {
         string ipaddress = Network.player.ipAddress;
         GUI.Box(new Rect(10, Screen.height - 50, 100, 50), ipaddress);
         GUI.Label(new Rect(20, Screen.height - 30, 100, 20), "Status" + client.isConnected);
 
         if(!client.isConnected)
         {
             Debug.Log("Waiting to connect");
             if(GUI.Button(new Rect(10,10,60,50),"Connect"))
             {
                 Connect();
             }
         }
     }
     void Start () {
         client = new NetworkClient();
     }
     
     void Connect()
     {
         client.Connect("192.168.43.205", 25000);
     }
 
     static public void SendJoystickInfo(float hDelta, float vDelta)
     {
         if(client.isConnected)
         {
             StringMessage msg = new StringMessage();
             msg.value = hDelta + "|" + vDelta;
             client.Send(888, msg);
         }
     }
 }




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

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

126 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 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 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 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 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 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

Unity UDP freezes if disconnected from server 2 Answers

connecting two people over the Internet 1 Answer

Server not receiving message? 1 Answer

Networking in a 2 player web game using a player as the server 0 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