ADVANCED TOPICS

ADVANCED TOPICS

Miscellaneous features that don't fit into the other chapters of the manual, but still need mentioning.

Redirection

Redirecting a specific player

In uLink, you can redirect a client connection to another server at any time. This is done by calling any one of the available ulink.Network.RedirectConnection methods. See the API docs for details on the various parameters that can be sent. Calling this method will force the client to disconnect from the server and then connect to a new, specified server. This will be a completely new connection, and no state is moved from the current server to the new one. See Handover methods mentioned the P2P chapter if you need to have state transferred to the new server.

Redirect all future players

You can also redirect all future client connections to a server. This is very handy when you wish to gracefully disable a server. For example, in an MMO game, when an old server should be replaced with a new server, it is possible to redirect all connection attempts to the to the new one. The following code, executed in the old server, accomplishes this.
uLink.Network.redirectIP = "192.168.1.121"; uLink.Network.redirectPort = 8091; uLink.Network.useRedirect = true;
When all players have logged off the old server (after a few hours when they stop playing the game) it is posible to stop the old server gracefully since it has no connections at this time. The switch from the old server to the new one is completed and not a single player connection have been lost in the transition.

Fine-tuning network parameters

uLink allows you to tweak a number of low-level network settings. These relate to timeouts, delays, connection attempts and things that may need to be adjusted for maximum network performance. You should be aware that while you are free to alter these settings, doing so without care can make connections unstable or reduce transmission efficiency. The default values have been carefully chosen for typical ethernet network conditions.
You can access the settings through the uLink.Network.config property which gives a reference to a uLink.NetworkConfig object. It has the following properties to set. All the properties can be read from and written to. You can update them at any time, before or after calling uLink.Network.Connect() or uLink.Network.InitializeServer().
  • timeBetweenPings
    This lets you set how often a client or server should send pings in seconds. If you decrease this value, uLink will send pings more often, increasing bandwidth. If you increase this value, less bandwidth will be used, but you risk connection timeout if many ping messages are being lost. You can change this independently for the client and the server.
  • timeoutDelay
    This lets you set how long a client or server should wait for a pong message, in seconds, before treating the connection as lost. This value should be altered together with the timeBetweenPings value. You can change this independently for the client and the server.
  • handshakeRetryDelay
    This sets how long the client should wait, in seconds, before trying to connect again if the first attempt fails when calling uLink.Network.Connect(). If you know that the server may be busy you can increase this vaule so that you don't flood the server with connection attempts. This value is only meaningful on the client.
  • handshakeRetriesMaxCount
    This sets how many times a client should try to connect to the server if it fails the first time, when calling uLink.Network.Connect(). If you know that the network between client and server drops many packets you can increase this so that eventually a connection attempt will reach the server. This value is only meaningful on the client.
  • maximumTransmissionUnit
    This sets the maximum number of bytes one packet can hold. If a data payload doesn't fit into one packet it will be fragmented over several packets, which increases CPU load at both ends of the connection. Setting it larger than the default may cause routers between the hosts to handle the packet very inefficiently. Do not modify this value unless you know exactly what you are doing!

RPC communication groups

Communication group index is supplied as an argument in the Instantiate() call. It is an extra option we recommmend to avoid. It is included in uLink to be backwards compatible with the Unity built-in network. But it is currently turned off in uLink 1.1. Just set the group number to 0 for all objects to avoid problems with group numbers.
Usage example: You could have one group for game data and one for chat communication. The game data group could be closed when loading a level while the chat group could be kept open so that players still can talk to each other.
Use uLink.Network.SetSendingEnabled() and uLink.Network.SetReceivingEnabled() to enable or disable the sending and receiving of messages in a specific group.