public void MessageReceived(NetworkComponents.IGridforceMessage message) { if (message is HostInformation) { HostInformation hostInformation = (HostInformation)(message); System.Diagnostics.Debug.WriteLine(hostInformation.ToString()); } }
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; }
// 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(); }
private static void OnMesageReceivedFromHost(NetworkComponents.TCPConnection connection, NetworkComponents.IGridforceMessage message) { Console.WriteLine("Host sent " + message.GetType().ToString()); }
public static byte[] Serialize(NetworkComponents.IGridforceMessage message) { if (message is HostInformation) return HostInformation.Serialize((HostInformation)(message)); return null; }
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(); }