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 /
  • Help Room /
avatar image
2
Question by madhusudan1997-sharma · Apr 19, 2016 at 04:08 PM · androidnetworkingmultiplayer

Android multiplayer using WiFi

Hello everyone, I want to develop an android game which go multiplayer over the wifi (something like "Doodle Army 2: Mini Militia"). I have tried everything which is available on the internet but nothing helped me. I made a game which can go multiplayer on the same system(computer) but when I try it on android devices(making one android device as hotspot and other to connect to it via wifi), it doesn't works. I don't know what is the problem. I am using the following script to handle all of the networking related tasks. Please help! Thank you.

using UnityEngine; using UnityEngine.Networking; using gui = UnityEngine.GUILayout;

public class Network : MonoBehaviour { public GameObject PlayerPrefab; string ip = "127.0.0.1"; private const string typeName = "typename"; private const string gameName = "gamename"; private HostData[] hostList;

 public void CreatePlayer()
 {
     connected = true;
     GameObject g = Network.Instantiate(PlayerPrefab, transform.position, Quaternion.identity, 1) as GameObject;
     GameObject.Find("PlayerCamera").GetComponent<Camera>().enabled = true;
     Destroy(GameObject.Find("MenuCamera"));
 }
 void OnDisconnectedFromServer()
 {
     connected = false;
 }
 void OnPlayerDisconnected(NetworkPlayer pl)
 {
     Network.DestroyPlayerObjects(pl);
 }
 void OnConnectedToServer()
 {
     Debug.Log("Connected to Server");
     CreatePlayer();
 }
 void OnServerInitialized()
 {
     Debug.Log("Server Initializied");
     CreatePlayer();
 }
 private void RefreshHostList()
 {
     MasterServer.RequestHostList(typeName);
 }
 void OnMasterServerEvent(MasterServerEvent msEvent)
 {
     if (msEvent == MasterServerEvent.HostListReceived)
         hostList = MasterServer.PollHostList();
 }
 bool connected;
 void OnGUI()
 {
     if (!connected)
     {
         ip = GUI.TextField(new Rect(5, 5, 150, 50), ip, 25);
         if (GUI.Button(new Rect(5, 70, 150, 70), "connect"))
         {
             Network.Connect(hostList[0]);      //Both ways are tried but
             Network.Connect("127.0.0.1", 25000, "");     //nothing works.
         }
         GUI.enabled = true;
         if (GUI.Button(new Rect(5, 150, 150, 70), "host"))
         {
             Network.InitializeServer(32, 25000, false);
             MasterServer.RegisterHost(typeName, gameName);
             Network.sendRate = 15;
         }
     }
 }

}

Comment
Add comment · Show 5
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 madhusudan1997-sharma · Apr 24, 2016 at 04:36 PM 0
Share

Please someone reply, I need help :(

avatar image Magnas94 · Aug 09, 2016 at 10:13 AM 0
Share

Heyy, @madhusudan1997.sharma , I just build a project in Unity 5.3 which runs over local multiplayer, (using hotspot), So I have solution to your problem. I see you are working on uNet. I have created my game in uNet too... So do let me know if you still need help . :)

avatar image amaanawati86 · Mar 17, 2017 at 09:54 PM 0
Share

Hii @$$anonymous$$agnas94, I am also making a multiplayer game. can u please help me. i want the devices to be connected using hotspot. Can u please explain the full thing as i am new to unity. Thank you

avatar image Magnas94 amaanawati86 · Mar 20, 2017 at 11:34 AM 0
Share

@RiAmazing @madhusudan1997-sharma @amaanawati86

Listen all, For mobile hotspot the best practice is to take your own IP, and substring it so that the last bit of ip is always .1 , FOR example , if I created hotspot from my device(i.e. if I am host) , then my ip would be something like : "xxx.xxx.xx.1"

But for any client , who is connected to my hotspot , his ID will be something like : "xxx.xxx.xx.a" where a is never 1 but is any random positive integer like 2,3,64,29 etc

so you just substring ur own ip and replace the last part by '1'.

Example : suppoese my ip is: myIP = "xxx.xxx.xx.92" string someAddress = myIP.Substring (0, 10) + ".1";

now this someAdress is what u use to connect to host on hotspot by running :

manager.networkAddress = someAddress;

avatar image AndersWhite · May 25, 2017 at 09:48 AM 0
Share

Hey, m working on same kinda project as yours so I picked up your script and dropped network manager script.But its not working,can you help me a bit with my project. It is to spawn to fabs over lan without internet.

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bamdad · Aug 29, 2016 at 04:57 AM

@madhusudan1997-sharma

You should use 192.168.43.1 for ip. It worked for me on a multiplayer hotspot game.

Comment
Add comment · Show 2 · 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 VMask25 · Jun 02, 2017 at 03:33 PM 0
Share

Sorry, I'm trying to make a LAN connection between two android devices for a game through my WIFI. But it works only with the IP 192.168.43.1, only with an hotspot connection and only when the HOST is the hotspot device...how can I do it works using WIFI?

avatar image tiwariavinash503 · Jun 16, 2018 at 10:32 PM 0
Share

hey everyone, I'm an absolute beginner. I am learning by making a game that has two modes in which player plays vs Computer and the other mode is multiplayer. 1. Can you people guide me how to do Ai mode along with $$anonymous$$ultiplayer? 2. How online multiplayer in Doodle army like games work? Thanks.

avatar image
1

Answer by fredfishgames · Aug 18, 2016 at 08:26 PM

you're trying to make the android device which is the client connect to itself. You need to replace the "127.0.0.1" with the ip address of the host device. I think you can find this somewhere in the wifi settings, but it should be the same for all android devices who are running mobile hotspot.

Sorry if you've tried this already.

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

Answer by RiAmazing · Jan 30, 2017 at 07:48 AM

@magnas94 I just build a project in Unity 5.3 which runs over local multiplayer, (using hotspot), So I have solution to your problem. I see you are working on uNet. I have created my game in uNet too... So do let me know if you still need help . :)

I also wanted to make the same game, can you help me?

Comment
Add comment · Show 4 · 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 madhusudan1997-sharma · Apr 18, 2017 at 06:37 PM 0
Share

I'm now good with the local and online multiplayer in Unity. If you need any help, just let me know.

avatar image guardian12397 madhusudan1997-sharma · Jun 08, 2017 at 12:08 PM 0
Share

bro I am also creating multiplayer game can u tell me how you were able to connect the devices via wifi....

avatar image degeta · Sep 08, 2017 at 05:58 PM 0
Share

@magnas94 Can you please share the project files .It would be really helpful. I'm also trying to learn on how to make multiplayer games.

avatar image sivaliZation · Dec 09, 2017 at 05:44 PM 0
Share

any help over a hotspot game would be more helpfull !

avatar image
0

Answer by Magnas94 · Feb 01, 2017 at 09:17 AM

@RiAmazing , Its good that you want to work on a similar type of game , so are you using uNet too ? and if you are , then will you be connecting your devices using WiFi, or mobile Hotspot ??

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

117 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

Related Questions

connecting 2 android devices without Internet 2 Answers

Multiplayer networking for Android 0 Answers

[HELP] Problem in multiplayer networking code in c# 0 Answers

How to add realtime game events without updating build? 1 Answer

Can i get names of some free LAN multiplayer assets?? 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