Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[LLAPI] How to connect to self? (Host)

Discussion in 'Multiplayer' started by Leoo, Jun 21, 2017.

  1. Leoo

    Leoo

    Joined:
    May 13, 2013
    Posts:
    96
    Hey guys, been trying to get some basic stuff done on LLAPI, something i cant seen to get is the actual HOST type of server, been trying to figure out how the HLAPI does it, but its quite hard to read from the bitbucket, how would any1 connect to its own server ?

    I hav tried to do a transport.addhost and then transport.connect, but some weird stuff happends... How do you guys do it?

    I think this is actually more of an "application" level problem, instead of actual llapi feature., something like just add a fake user with uid of -1 to user lists , hlapi does something like this? right?.

    Thanks.
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    If you are fairly new to networking, I probably wouldn't recommend trying to build a peer-hosted network using the LLAPI. Peer-hosted networks are quite difficult to get working nicely due to how much you rely on the hardware of your peers/players. If you absolutely want to go the route of a peer-hosted setup, you'll actually find it much easier to do it using the HLAPI (many of the issues related to peer-hosted networks have been solved for you in the HLAPI).

    If you are keen to work with the LLAPI, I recommend looking into a server-client setup. This setup is similar to a peer-hosted setup, however the "host" is replaced with a permanent/dedicated server that you run your server-side/server application (built in unity) on. This immediately solves so many problems but comes at the cost of running your own dedicated server. I personally use google cloud for this though and the cost is very reasonable (although there are cheaper options). Note too that it's pretty simple to run the server-application on your local machine while testing.

    Hopefully this helps, good luck!
     
    Leoo likes this.
  3. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    The LLAPI is very low level, it is opening a socket on your device and waiting for connections. You don't have to connect to this socket. You could have a player list on the hosts device, if you receive a connectionEvent you can add this player to the list. After opening the socket you can just add yourself to the list, no need to make a network connection to yourself.
     
    Leoo likes this.
  4. Kombiice

    Kombiice

    Joined:
    Jan 20, 2015
    Posts:
    64
    Really need to look at peer to peer.
     
    Leoo likes this.
  5. Leoo

    Leoo

    Joined:
    May 13, 2013
    Posts:
    96
    @donnysobonny I understand what you are trying to say, but i've been working with the HLAPI for more than 5 months now, and i am doing almost every type of "override" and doing my own "message (de)/serialization", so at the end, i am already doing tons of work building sadly another layer on top of HLAPI to be able to achieve what i need, even so many simple stuff that i had to hack to get done is just nonsense. I feel like i could go way cleaner avoiding "network manager, and others.." , BUT, i am actually quite interested to know what could be an example of a "issue related to peer-hosted networks" + "hadware rely" you are talking about?

    Am building a PC only game, player hosted + possibility of headless server aswell.

    @Pidon Thank you, it is an application level problem.
     
  6. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    @Leoo

    Despite your 5 months of playing around with the HLAPI, there is evidence that you are making mistakes in what you are doing, when considering good practice and general practice when it comes to networking and programming in general. for starters:
    • Don't implement or rely on work-arounds. To be more clear here, a "work-around" is when the tool that you use doesn't do what you want it to, so you hack away at it or make it do something that it wasn't designed to do. If you have ever built anything complicated, you'll now how easy it is for someone to come in and mess everything up, UNET is no different to this. So unless you know the whole architecture of the framework itself, hacking away at it to make it do what you want to do is only going to set you up with issues
    • Whenever you are considering using a framework always take the time to understand what the framework does. If it doesn't do what you want, it's likely it's the wrong framework but make sure you spend enough time coming to that conclusion before you do. The fact that you're having to "build another layer on top of the HLAPI" suggests to me you haven't taken the time to fully understand the HLAPI... I'm not sure why you would want to or need to build another layer on top of a convenience solution. That's just a bad idea in general.
    As for your question related to the issues of peer-hosted networks, I know that a forum is a place where you should be able to seek help/advice with what you are doing but I can't help but feel that you are jumping in far too deep without taking time to understand what it is that you are doing. So, instead of answering that question I will suggest that you take a step back and read up on peer-hosted and client-server architectures, there are plenty of resources on these topics.

    Again, take the time here. Multiplayer/network programming is not simple, regardless of your past experiences.

    Good luck!
     
    Leoo likes this.