Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

How to use LLAPI with HLAPI ?

Discussion in 'Connected Games' started by Adurnat, Jun 8, 2017.

  1. Adurnat

    Adurnat

    Joined:
    Oct 13, 2016
    Posts:
    7
    Hello everyone,
    I'm discovering the joys of networking with unity.
    I have 2 different projects, one server and one client (and yes it absolutely has to be 2 different projects) and I am debugging both on the same local machine.

    I'm using HLAPI in order to synchronize syncvar which works perfectly fine in order to send server to client information. However since they are two different projects, it seems that I can't send commands from client to server, though my knowledge might be quite limited in that area.

    So now I'm trying to use LLAPI in order to grant myself the flexibility needed. I followed this tutorial which seems to work fine as a standalone but it seems that there are some conflicts when I'm trying to add this in my project and I'm not sure how to proceed.
    Do I call StartServer() / StartClient() and then open a socket and a port? I'm guessing the NetworkManager has already done that for me so how do I use it ?
    When I try this I have an error : "Cannot open socket on ip{...} and port {...}:check please your network, most probably port has been already occupied."

    Also the LLAPI documentation is simply inexistant so I have no idea where to look at.
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    Well, to get you going in the right direction:
    • the layers that exist between the LLAPI and HLAPI include a custom format that messages are sent in. So, in order to use the LLAPI along with the HLAPI, you would need to understand the format that unity use when messages are being sent in order to understand/decipher them. I tried doing this a long time ago, and although I found some success, UNET is regularly improving the messages being sent and therefore even if you were to decipher the format, it will likely change in the future. Ultimately, just don't do this. Either stick to using nothing but the LLAPI, or use what you need from the HLAPI.
    • Secondly, there is literally no reason that I can think of why you would want separated projects and/or use both the HLAPI and LLAPI at the same time. One of the best things about UNET is that it is a networking framework that is nicely integrated into unity, so take advantage of that and just build a single project and work on your client/server side in the same project. For ease, I normally separate my "server" and "client" stuff into separate scenes, so that they can easily be built into separate applications. I would suggest to do the same.
    Unless there is a really good reason why you're doing what you are trying to do, you're only going to make your life very difficult.

    Hopefully this helps, good luck!
     
  3. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    255
    I'll start with a suggestion for everyone. Go to https://bitbucket.org/Unity-Technologies/networking and get a copy of the HLAPI. That will do two things for you. One, it's a working example of how to implement something using the LLAPI, and two, it will leave you with a better understanding of the HLAPI. As a bonus, you can modify the HLAPI if needed. Don't be scared of the LLAPI. Once you see how the HLAPI works, you'll see the LLAPI is pretty simple to use. Any time you create a custom message, that is LLAPI, and it's pretty much all it does. Almost everything else is glue...

    Moving on, though, to send commands, you need a NetworkIdentity with authority. You can grant that from the server by setting an object as a player with AddPlayerForConnection or calling AddClientAuthority to the object (which then allows you to remove auth if needed, but good luck with that!)
     
  4. Adurnat

    Adurnat

    Joined:
    Oct 13, 2016
    Posts:
    7
    Thanks for the great answers.

    @donnysobonny
    The reason why I need two projects is because I have to deploy one build for my HoloLens and another one for PC in order to make them communicate. I added to my project a Microsoft package called HoloToolkit which is a great API for HoloLens but even on a empty project, the simple action of adding this package makes it completely impossible to build for PC (dozens of namespace errors, among other things). But if you have any idea on how to fix that it would be a salvation.

    @angusmf
    I'll dig into the link, thank you. I used custom messages before in order to communicate between two HoloLens but it wasn't with Unet.
    Concerning the commands, I have a player which is not a prefab but a gameobject in the hierarchy, with a network identity set to local player authority. As I said this configuration works perfectly fine with SyncVars but during Play Mode the player's state isn't convenient: IsServer, Has Authority and Is Local Player are set to False which prevents the player to send commands. Can I force those states to be true with like AddClientAuthority ?
    So if I understand what you're saying , the Player supposed to send the commands is the player's prefab on the server side that is auto created on the client? I tried this but there seems to be an issue because I'm working on two different projects : "Failed to spawn server object, assetId=43cdf252xx..."
     
    Last edited: Jun 9, 2017
  5. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    208
    I wouldn't be the best person to ask, however in the interest of best practice and also making your life a HELL of a lot easier, I would highly recommend solving problems rather than working around them. In this case, working out how to build both your client and server in the same project is going to make your life so much easier.

    Have you tried posting around about the issues that you're having with the HoloLens API?
     
  6. Adurnat

    Adurnat

    Joined:
    Oct 13, 2016
    Posts:
    7
    Yes, I have asked the question on the Microsoft HoloLens Dev Forum here but I haven't received an answer yet.

    I'll follow your advice and will try to have only one project. If I get out of this with a solution I'll post it here.
    Thanks for the help and suggestions.
     
  7. Adurnat

    Adurnat

    Joined:
    Oct 13, 2016
    Posts:
    7
  8. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    738
    Have you checked LocalPlayerAuthority on the player prefab?
     
unityunity