You can easily choose between the different transport protocols when creating connections:
//Create a connectionInfo object ConnectionInfo connInfo = new ConnectionInfo("192.168.0.1", 10000); //Create a new TCP connection using default options //A connection is returned via a static method instead of // using a new operator to ensure thread safety Connection newTCPConn = TCPConnection.GetConnection(connInfo); //Create a new UDP connection using default options //The parameter UDPOptions is for future "reliable" UDP features (currently unused). Connection newUDPConn = UDPConnection.GetConnection(connInfo, UDPOptions.None);
For more information on these specific methods please see TCPConnection.GetConnection and UDPConnection.GetConnection. Once a connection has been created it can be used in a large number of ways, for a full reference see our online API here, regardless of the connection type used:
////////////////////////////////////////// //Here are some common connection usages ////////////////////////////////////////// //Append a connection specific packet handler //We will trigger the method "MethodToRunForStringMessage" // when a packet of type "StringMessage" is recieved newConn.AppendIncomingPacketHandler<string>("StringMessage", MethodToRunForStringMessage, NetworkComms.DefaultSendReceiveOptions); //Append a connection specific close handler //We will trigger the method "MethodToRunOnConnectionClose" // if this connection is closed / disconnected. newConn.AppendShutdownHandler(MethodToRunOnConnectionClose); //Send a customObject using a packet of type "CustomObject1" newConn.SendObject("CustomObject1", customObject); //Send a customObject using a packet of type "CustomObject1" and // then wait synchronously for the remote end to return a // CustomObject2 using a packet of type "CustomObject2" CustomObject2 customObject2 = newConn.SendReceiveObject<CustomObject1, CustomObject2>("CustomObject1", "CustomObject2", 1000, customObject); //Close the connection, triggering any close handlers newConn.CloseConnection(false);
We have a tutorial further discussing the synchronous send receive methodology here and UDP specific features such as broadcasting here. If you have any questions regarding connections please feel free to leave a comment or post on our forums.