Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Unity Multiplayer UNet HLAPI Sample - custom connection classes

Discussion in 'Multiplayer Networking' started by seanr, Dec 22, 2015.

  1. seanr


    Unity Technologies

    Sep 22, 2014
    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.

    • 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:

    JosephHK, QuaintShanty and DrSpritz like this.