Beispiel #1
0
        private Socket CreateTrackSocket(ConnectionType type)
        {
            var hostname = Environment.GetEnvironmentVariable("RACE_TRACK_HOSTNAME");

            if (hostname == null)
            {
                hostname = "localhost";
            }

            var portString = Environment.GetEnvironmentVariable("RACE_TRACK_PORT");
            var port       = 11000;

            if (portString != null)
            {
                port = Int32.Parse(portString);
            }

            try
            {
                IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
                IPAddress   ipAddress  = ipHostInfo.AddressList[0];
                Socket      client     = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                var state = new ConnectStateObject(client, type);
                client.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), state);
                return(client);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Beispiel #2
0
 private Socket CreateTrackSocket(ConnectionType type)
 {
     try
     {
         IPAddress ipAddress = GetRaceTrackIp();
         int       port      = GetRaceTrackPort();
         Socket    client    = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         var       state     = new ConnectStateObject(client, type);
         client.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), state);
         return(client);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         throw;
     }
 }