/// <summary>
        /// Connects to the socket and starts listening
        /// </summary>
        public static void Connect()
        {
            SocketClientManager.udpSocket = new DatagramSocket();
            SocketClientManager.udpSocket.MessageReceived += SocketClientManager.MessageReceived;

            // Calling the binding async
            SocketClientManager.Bind();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a message
        /// </summary>
        /// <param name="nm">The <c cref="NetworkMessage">network message</c> that needs to be send</param>
        public static void SendMessage(NetworkMessage nm)
        {
            // Write the data into a byte array
            byte[] byteArray = new byte[nm.Content.Length + 1];

            byteArray[0] = nm.MessageId;

            // Write the content into the array
            var i = 1;

            foreach (byte messageData in nm.Content)
            {
                byteArray[i] = messageData;
                ++i;
            }

            PrintDebug("Sending message");

            SocketClientManager.SendMessageToSocket(byteArray);
        }