Пример #1
0
 public static void CloseServer()
 {
     if (UDPBroadCastSocket != null)
     {
         UDPBroadCastSocket.Close();
         UDPBroadCastSocket = null;
     }
     if (TCPBroadCastTcpListener != null)
     {
         TCPBroadCastTcpListener.Stop();
         TCPBroadCastTcpListener = null;
     }
 }
Пример #2
0
 private static void UDPAsyncCallbackServer(IAsyncResult result)
 {
     if (UDPBroadCastSocket != null)
     {
         try
         {
             Output.WriteLine($"\tPlayer has sent out a Discovery call from: {UDPRemoteEndPoint}");
             int    size = UDPBroadCastSocket.EndReceiveFrom(result, ref UDPRemoteEndPoint);
             byte[] initialBytesToSend = new byte[10];
             UDPBroadCastSocket.SendTo(initialBytesToSend, UDPRemoteEndPoint);
             UDPBeginReceiveDiscoveryCalls();
         }
         catch (Exception exception)
         {
             Output.WriteLine($"\tError in AsyncCallback of Discovery Server: \n{exception}");
         }
     }
 }
Пример #3
0
 private static void UDPBeginReceiveDiscoveryCalls()
 {
     UDPBroadCastSocket.BeginReceiveFrom(new byte[1024], 0, 1024, SocketFlags.None, ref UDPRemoteEndPoint, new AsyncCallback(UDPAsyncCallbackServer), null);
 }