Search Unity

UNet HLAPI Sample - custom connection classes

Discussion in 'UNet' started by seanr, Dec 22, 2015.

  1. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Attached is a UNet HLAPI advanced usage sample that shows custom connection classes derived from the NetworkConnection class.

    This sample uses a "RoomClientConnection" class and a "RoomProxyServerConnection" class to implement a proxy server for HLAPI traffic. The Room Proxy Server is a combined room manager and proxy server. The custom connection classes add a 4 byte header to network traffic (to identify the source or destination) when required, and the RoomClientVirtualConnection class is used on the host to route traffic to the right clients via the proxy server.

    This server is not terribly efficient as it copies every message that requires a header. There is a lot of logging enabled too. I have only tested this up to 16 clients in 4 rooms.

    This sample also uses NetworkServer.AddExternalConnection() and NetworkManager.UseExternalClient(). These methods allow connections and client instances created "manually" outside of the normal HLAPI NetworkManager flow to be used with the system.

    The RoomProxyServer can be run in the same process as a host or client, or in it's own process.

    There is a simple runtime UI for start/stop the proxy server, and for the RoomClient to create/find rooms.

    The editor components for the RoomProxyServer and RoomClient show the connections and rooms that they are managing.


    Instructions:
    • start a client in the menu scene
    • start the proxy server with UI button
    • Connect the RoomClient to the proxy server
    • Create a room - a game should start
    • start another client in the menu scene
    • Connect the RoomClient to the proxy server
    • List rooms - the created room should appear
    • join the room - should enter the created game
    • traffic is now running through the proxy server

    This sample require Unity version 5.3.0p1
     

    Attached Files: