public async Task startListener() { try { listener = new DatagramSocket(); listener.MessageReceived += MessageReceived; await listener.BindEndpointAsync(new HostName(IPAdress.LocalIPAddress()), portListener); playPage.DisplayMessages(name + " :UDP Listener [local]:" + portListener + " started"); } catch (Exception ex) { playPage.DisplayMessages(name + " :ERROR: UDP Listener [local]:" + portListener + " started\n" + ex.ToString()); } }
private void MessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args) { try { DataReader reader = args.GetDataReader(); reader.InputStreamOptions = InputStreamOptions.Partial; uint bytesRead = reader.UnconsumedBufferLength; String message = reader.ReadString(bytesRead); playPage.DisplayMessages(name + " :Message received [" + args.RemoteAddress.DisplayName.ToString() + "]:" + args.RemotePort + ": " + message); SendMessage(IPAdress.LocalIPAddress() + " " + name, args.RemoteAddress.DisplayName.ToString(), portSender); reader.Dispose(); } catch (Exception ex) { playPage.DisplayMessages(name + " :ERROR: Message received from:\n" + ex.ToString()); } }
public GameServer(PlayPage playpage, string name, string portUDP1, string portUDP2, string portTCP1L, string portTCP1S, string portTCP2L, string portTCP2S, string portTCP3L, string portTCP3S) { serverBussyflag = false; this.playpage = playpage; gameData = new GameData(); serverUDP = new UDPListener(playpage, name, portUDP1, portUDP2); firstConnectionClient = TCPClientRemote.Instance; firstConnectionClient.initTCPClient(playpage, name); firstConnectionClient.initListener(portTCP3L); firstConnectionClient.Received += firstConnectionReceived; this.portTCP3S = portTCP3S; this.portTCP2S = portTCP2S; this.portTCP1L = portTCP1L; server = new Server(playpage, portTCP2S); server.Received1 += onServerRecieved1; server.Received2 += onServerRecieved2; client = TCPClientRemote.Instance; client.initTCPClient(playpage, name); client.Received += OnReceived1; server.addForPlayer1Listener(portTCP1L); client.initListener(portTCP1S); server.addForPlayer2Listener(portTCP2L); client.initSender(portTCP1L, IPAdress.LocalIPAddress()); server.addForPlayer1Sender(portTCP1S, IPAdress.LocalIPAddress()); server.addForPlayer2Listener(portTCP2L); }