1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Unity Multiplayer UNet HLAPI Sample - custom connection classes

Discussion in 'Multiplayer Networking' 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:

    JosephHK, QuaintShanty and DrSpritz like this.