1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 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

    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.