Exemplo n.º 1
0
 private void UDPListenerReceiveCallback(System.IAsyncResult ar)
 {
     System.Net.Sockets.Socket serversocket = ((StateObject)ar.AsyncState).ServerSocket;
     byte[] buffer = ((StateObject)ar.AsyncState).Buffer;
     try
     {
         System.Net.Sockets.SocketFlags         sf     = System.Net.Sockets.SocketFlags.None;
         System.Net.EndPoint                    client = new System.Net.IPEndPoint(System.Net.IPAddress.None, 0);
         System.Net.Sockets.IPPacketInformation pi     = new System.Net.Sockets.IPPacketInformation();
         int received = serversocket.EndReceiveMessageFrom(ar, ref sf, ref client, out pi);
         if (received > 0)
         {
             string[] clientinformations = System.Text.Encoding.Unicode.GetString(buffer, 0, received).Split('|');
             if (clientinformations.Length >= 3)
             {
                 switch ((Commands)int.Parse(clientinformations[0]))
                 {
                 case Commands.GetServerInformations:
                     Version clientversion = new Version(byte.Parse(clientinformations[1]), byte.Parse(clientinformations[2]));
                     if (clientversion.Major < Version.Major || (clientversion.Major == Version.Major && clientversion.Minor <= Version.Minor))
                     {
                         string serverinformation = "Wall Street Game Server on " + System.Environment.MachineName;
                         if (GetServerInformationEvent != null)
                         {
                             serverinformation = GetServerInformationEvent();
                             if (serverinformation == null)
                             {
                                 serverinformation = String.Empty;
                             }
                             serverinformation = serverinformation.Replace("|", null);
                         }
                         serverinformation += '|' + Version.Major.ToString() + '|' + Version.Minor.ToString() + '|';
                         serversocket.SendTo(System.Text.Encoding.Unicode.GetBytes(serverinformation), client);
                     }
                     break;
                 }
             }
         }
     }
     catch (System.ObjectDisposedException)
     {
         // The socket has been closed.
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
 public int ReceiveMessageFrom(byte[] buffer, int offset, int size, ref System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, out System.Net.Sockets.IPPacketInformation ipPacketInformation)
 {
     throw null;
 }
Exemplo n.º 3
0
 public int ReceiveMessageFrom(byte[] buffer, int offset, int size, ref System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, out System.Net.Sockets.IPPacketInformation ipPacketInformation)
 {
     ipPacketInformation = default(System.Net.Sockets.IPPacketInformation); return(default(int));
 }
Exemplo n.º 4
0
 public int EndReceiveMessageFrom(System.IAsyncResult asyncResult, ref System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint endPoint, out System.Net.Sockets.IPPacketInformation ipPacketInformation)
 {
     ipPacketInformation = default(System.Net.Sockets.IPPacketInformation); return(default(int));
 }