예제 #1
0
 public void MessageReceived(NetworkComponents.IGridforceMessage message)
 {
     if (message is HostInformation)
     {
         HostInformation hostInformation = (HostInformation)(message);
         System.Diagnostics.Debug.WriteLine(hostInformation.ToString());
     }
 }
예제 #2
0
        public static byte[] Serialize(NetworkComponents.IGridforceMessage message)
        {
            if (message is HostInformation)
                return HostInformation.Serialize((HostInformation)(message));
            else if (message is UserInformation)
                return UserInformation.Serialize((UserInformation)(message));
            else if (message is JoinRequest)
                return JoinRequest.Serialize((JoinRequest)(message));

            return null;
        }
예제 #3
0
            // Constructor
            public UDPReceiver(NetworkComponents.MessageProc messageProc)
            {
                this.messageProc = messageProc;

                this.udpClient = new UdpClient();
                this.udpClient.Client.ReceiveTimeout = 250;
                this.udpClient.ExclusiveAddressUse = false;
                this.localEndPoint = new IPEndPoint(IPAddress.Any, NetworkComponents.gamePort);
                this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                this.udpClient.ExclusiveAddressUse = false;
                this.udpClient.Client.Bind(this.localEndPoint);
                this.udpClient.JoinMulticastGroup(IPAddress.Parse(NetworkComponents.multicastIP), 50);

                this.receiverThread = new Thread(this.Receive);
                this.receiverThread.Name = "Gridforce UDP Receiver";
                this.receiverThread.IsBackground = true;
                this.receiverThread.Start();
            }
예제 #4
0
 private static void OnMesageReceivedFromHost(NetworkComponents.TCPConnection connection, NetworkComponents.IGridforceMessage message)
 {
     Console.WriteLine("Host sent " + message.GetType().ToString());
 }
예제 #5
0
        public static byte[] Serialize(NetworkComponents.IGridforceMessage message)
        {
            if (message is HostInformation)
                return HostInformation.Serialize((HostInformation)(message));

            return null;
        }
예제 #6
0
            private NetworkComponents.MessageProc messageProc = null;		// Message to call on receiving message

            // Constructor
            public UDPReceiver(NetworkComponents.MessageProc messageProc)
            {
                this.messageProc = messageProc;
                Task task = Task.Run(async () => { await this.Connect(); });
                task.Wait();
            }