The server can only register each packet type once. Therefore, on serverside we have to use the “RegisterStaticPacketHandler” method. That will map a packettype directly to the given delegate. In the following example we start to listen to a “CalculationRequest” after a connection has been established.

connection.RegisterStaticPacketHandler registers the generic <CalculationRequest> to the delegate “calculationReceived”. If the client sends a “CalculationRequest” the server is going to receive that packet directly in the “calculationReceived” method. Because we directly receive a “CalculationRequest” we don’t need any cast.