Search Unity

Help setting up a lan connection?

Discussion in 'Multiplayer' started by Gekitatsu, Dec 27, 2011.

  1. Gekitatsu

    Gekitatsu

    Joined:
    Dec 27, 2011
    Posts:
    7
    Hello everyone,

    I'm fairly new to using unity and I'm looking for a way to simply make a lan game between two computers. I've watched this great video about unity networking at http://cgcookie.com/unity/2011/12/20/introduction-to-networking-in-unity/ but neither of the computers I am working with have access to the internet. So... how can I go about doing the same thing in the video but without connecting to the internet? So you don't have the watch the video pretty much I just want each person in the game to have a block and be able to control it. I already have the block controlling down (the easy part) I just can't seem to find out how to setup a lan connection in unity. Thank you in advance.

    :eek:
     
  2. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,286
    You can easily connect via local network. Have other clients connect to the 127.0.0.1 host. Should work fine , i do this kind of networking almost exclusively. (Cause im not really good enough with other unity networking yet, lol).
     
  3. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    Other clients couldn't possibly connect to anything in the 127.0.0.0/8, as that entire network is dedicated to loopback activity. You have two ways to do this: have clients query the LAN and find servers, enumerate them, and provide a list to the player (harder and probably beyond your skills at this point) or have clients just enter the IP address of the system which is running the server instance they wish to join (much easier).
     
  4. Gekitatsu

    Gekitatsu

    Joined:
    Dec 27, 2011
    Posts:
    7
    JRavey your second point seems to be the easiest method, but how do I set it up? I assume I create a server via Network. then all I need is have the other program call Network.connect(main computer server ip)? My problem is every guide I find shows how to set up a network via a online server, but not like how you mentioned.
     
  5. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    Actually, you basically covered it. On the server, you get the server started and listening, then you tell the clients to connect to the server's IP address (don't forget the port number).

    For that to work, you can either hard code it or have a simple GUI with a text string and a button. Making that GUI is covered quite handily in tutorials and the documentation.

    More than likely, but it doesn't technically have to be, your servers' internal IP will start with 10. or 192.168. This will absolutely not work over the Internet of course, but should let you get started on making your game networked.
     
  6. Gekitatsu

    Gekitatsu

    Joined:
    Dec 27, 2011
    Posts:
    7
    Thanks JRavey I got it to work. I am now able to connect to my server (host computer) and see how many connections I have to that computer. I still have alot of work to do, but at least now I have a foundation to build on. Thanks.
     
  7. TheCasual

    TheCasual

    Joined:
    Sep 30, 2010
    Posts:
    1,286
    Ahh yea , my bad 192.168,***.** , haha , my bad to early when i read it :p
     
  8. Gekitatsu

    Gekitatsu

    Joined:
    Dec 27, 2011
    Posts:
    7
    Don't worry about it I knew what you meant. I just used ipconfig in console to find the correct address.
     
  9. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    Rather than write up everything, I found a tutorial that shows how you could do a basic UDP broadcast on the LAN or at least get you started. Each server would have to listen and reply, each client would have to send and listen for the reply. When you get the replies, you can just enumerate them into some collection you think would work best and present those to the user. At the very least, it might be a good programming exercise. In the age of the Internet, I don't know how helpful this would be, but it might be of some use at a later date.
     
  10. hersheys72

    hersheys72

    Joined:
    Sep 4, 2015
    Posts:
    7
    I struggled with this for a while, a few things you need for LAN:
    - Goto multiplayer.unity3d.com and sign up for a new game, which will get you a UNET ID.
    - In the 'Services' tab inside Unity which is near the inspector usually, enter your ID and link the game with it. There will be a multiplayer section that you can click on to see its all set up
    - On windows, in command prompt type 'ipconfig' to get your internal IP address for the computer which will be the host, usually 192.168.0.something
    - if using the networking HUD, put this 192 number into the space where it says localhost, and click the client button (for the client) after you have the host running
    :)
     
  11. JesusChrist17

    JesusChrist17

    Joined:
    Sep 17, 2016
    Posts:
    12
    how can i do the set up but in lan? ( using unet network manager )