Example #1
0
 internal void DnsAndConnect()
 {
     try
     {
         lock (this.syncer)
         {
             this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             this.sock.Connect(IPhotonSocket.GetIpAddress(this.ServerAddress), this.ServerPort);
             this.State = PhotonSocketState.Connected;
         }
     }
     catch (SecurityException ex)
     {
         if (this.ReportDebugOfLevel(DebugLevel.ERROR))
         {
             this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + ex.ToString());
         }
         this.HandleException(StatusCode.SecurityExceptionOnConnect);
         return;
     }
     catch (Exception ex)
     {
         if (this.ReportDebugOfLevel(DebugLevel.ERROR))
         {
             this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + ex.ToString());
         }
         this.HandleException(StatusCode.ExceptionOnConnect);
         return;
     }
     new Thread(new ThreadStart(this.ReceiveLoop))
     {
         Name         = "photon receive thread",
         IsBackground = true
     }.Start();
 }
Example #2
0
        internal void DnsAndConnect()
        {
            IPAddress ipAddress = null;

            try
            {
                ipAddress = IPhotonSocket.GetIpAddress(this.ServerAddress);
                if (ipAddress == null)
                {
                    // this covers cases of failed DNS lookup and bad addresses.
                    throw new ArgumentException("Invalid IPAddress. Address: " + this.ServerAddress);
                }

                lock (this.syncer)
                {
                    if (this.State == PhotonSocketState.Disconnecting || this.State == PhotonSocketState.Disconnected)
                    {
                        return;
                    }

                    this.sock = new Socket(ipAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.Connect(ipAddress, this.ServerPort);

                    this.AddressResolvedAsIpv6 = this.IsIpv6SimpleCheck(ipAddress);
                    this.State = PhotonSocketState.Connected;

                    this.peerBase.OnConnect();
                }
            }
            catch (SecurityException se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ServerAddress + "' (" + ((ipAddress == null) ? "" : ipAddress.AddressFamily.ToString()) + ") failed: " + se.ToString());
                }

                this.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ServerAddress + "' (" + ((ipAddress == null) ? "" : ipAddress.AddressFamily.ToString()) + ") failed: " + se.ToString());
                }

                this.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }

            Thread run = new Thread(new ThreadStart(ReceiveLoop));

            run.Name         = "photon receive thread";
            run.IsBackground = true;
            run.Start();
        }
        internal void DnsAndConnect()
        {
            IPAddress ipAddress = null;

            try
            {
                lock (this.syncer)
                {
                    ipAddress = IPhotonSocket.GetIpAddress(this.ServerAddress);
                    if (ipAddress == null)
                    {
                        throw new ArgumentException("Invalid IPAddress. Address: " + this.ServerAddress);
                    }
                    if (ipAddress.AddressFamily != AddressFamily.InterNetwork && ipAddress.AddressFamily != AddressFamily.InterNetworkV6)
                    {
                        throw new ArgumentException("AddressFamily '" + ipAddress.AddressFamily + "' not supported. Address: " + this.ServerAddress);
                    }

                    this.sock = new Socket(ipAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.Connect(ipAddress, this.ServerPort);

                    this.AddressResolvedAsIpv6 = (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6);
                    this.State = PhotonSocketState.Connected;

                    this.peerBase.OnConnect();
                }
            }
            catch (SecurityException se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ServerAddress + "' (" + ((ipAddress == null) ? "": ipAddress.AddressFamily.ToString()) + ") failed: " + se.ToString());
                }

                this.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ServerAddress + "' (" + ((ipAddress == null) ? "" : ipAddress.AddressFamily.ToString()) + ") failed: " + se.ToString());
                }

                this.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }

            Thread run = new Thread(new ThreadStart(ReceiveLoop));

            run.Name         = "photon receive thread";
            run.IsBackground = true;
            run.Start();
        }
 public void DnsAndConnect()
 {
     try
     {
         IPAddress ipAddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
         bool      flag      = ipAddress == null;
         if (flag)
         {
             throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
         }
         this.sock                = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         this.sock.NoDelay        = true;
         this.sock.ReceiveTimeout = this.peerBase.DisconnectTimeout;
         this.sock.SendTimeout    = this.peerBase.DisconnectTimeout;
         this.sock.Connect(ipAddress, base.ServerPort);
         base.AddressResolvedAsIpv6 = base.IsIpv6SimpleCheck(ipAddress);
         base.State = PhotonSocketState.Connected;
         this.peerBase.OnConnect();
     }
     catch (SecurityException ex)
     {
         bool flag2 = base.ReportDebugOfLevel(DebugLevel.ERROR);
         if (flag2)
         {
             base.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + base.ServerAddress + "' failed: " + ex.ToString());
         }
         base.HandleException(StatusCode.SecurityExceptionOnConnect);
         return;
     }
     catch (Exception ex2)
     {
         bool flag3 = base.ReportDebugOfLevel(DebugLevel.ERROR);
         if (flag3)
         {
             base.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + base.ServerAddress + "' failed: " + ex2.ToString());
         }
         base.HandleException(StatusCode.ExceptionOnConnect);
         return;
     }
     new Thread(new ThreadStart(this.ReceiveLoop))
     {
         Name         = "photon receive thread",
         IsBackground = true
     }.Start();
 }
        internal void DnsAndConnect()
        {
            try
            {
                lock (this.syncer)
                {
                    IPAddress ipAddress = IPhotonSocket.GetIpAddress(this.ServerAddress);
                    if (ipAddress == null)
                    {
                        throw new ArgumentException("DNS failed to resolve for address: " + this.ServerAddress);
                    }

                    this.AddressResolvedAsIpv6 = ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;

                    this.sock = new WebSocket(new Uri(this.ConnectAddress));
                }
            }
            catch (SecurityException se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ConnectAddress + "' failed: " + se.ToString());
                }

                this.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ConnectAddress + "' failed: " + se.ToString());
                }

                this.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }

            Thread run = new Thread(new ThreadStart(this.ReceiveLoop));

            run.Name         = "photon receive thread";
            run.IsBackground = true;
            run.Start();
        }
Example #6
0
        internal void DnsAndConnect()
        {
            //Discarded unreachable code: IL_008b, IL_00c9
            try
            {
                lock (syncer)
                {
                    sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    IPAddress ipAddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
                    sock.Connect(ipAddress, base.ServerPort);
                    base.State = PhotonSocketState.Connected;
                }
            }
            catch (SecurityException ex)
            {
                if (ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + ex.ToString());
                }
                HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception ex2)
            {
                if (ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, "Connect() failed: " + ex2.ToString());
                }
                HandleException(StatusCode.ExceptionOnConnect);
                return;
            }
            Thread thread = new Thread(ReceiveLoop);

            thread.Name         = "photon receive thread";
            thread.IsBackground = true;
            thread.Start();
        }
Example #7
0
        // Token: 0x06003E53 RID: 15955 RVA: 0x001398CC File Offset: 0x00137CCC
        internal void DnsAndConnect()
        {
            IPAddress ipaddress = null;

            try
            {
                object obj = this.syncer;
                lock (obj)
                {
                    ipaddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
                    if (ipaddress == null)
                    {
                        throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
                    }
                    if (ipaddress.AddressFamily != AddressFamily.InterNetwork && ipaddress.AddressFamily != AddressFamily.InterNetworkV6)
                    {
                        throw new ArgumentException(string.Concat(new object[]
                        {
                            "AddressFamily '",
                            ipaddress.AddressFamily,
                            "' not supported. Address: ",
                            base.ServerAddress
                        }));
                    }
                    this.sock = new Socket(ipaddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.Connect(ipaddress, base.ServerPort);
                    base.AddressResolvedAsIpv6 = (ipaddress.AddressFamily == AddressFamily.InterNetworkV6);
                    base.State = PhotonSocketState.Connected;
                    this.peerBase.OnConnect();
                }
            }
            catch (SecurityException ex)
            {
                if (base.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (ipaddress != null) ? ipaddress.AddressFamily.ToString() : string.Empty,
                        ") failed: ",
                        ex.ToString()
                    }));
                }
                base.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception ex2)
            {
                if (base.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (ipaddress != null) ? ipaddress.AddressFamily.ToString() : string.Empty,
                        ") failed: ",
                        ex2.ToString()
                    }));
                }
                base.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }
            new Thread(new ThreadStart(this.ReceiveLoop))
            {
                Name         = "photon receive thread",
                IsBackground = true
            }.Start();
        }
Example #8
0
        /// <summary>Internally used by this class to resolve the hostname to IP.</summary>
        internal void DnsAndConnect()
        {
            try
            {
                IPAddress ipAddress = IPhotonSocket.GetIpAddress(this.ServerAddress);
                if (ipAddress == null)
                {
                    throw new ArgumentException("DNS failed to resolve for address: " + this.ServerAddress);
                }

                this.AddressResolvedAsIpv6 = ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;


                if (this.State != PhotonSocketState.Connecting)
                {
                    return;
                }
                this.sock = new WebSocket(new Uri(this.ConnectAddress));
                this.sock.Connect();

                while (this.sock != null && !this.sock.Connected && this.sock.Error == null)
                {
                    Thread.Sleep(0);
                }

                if (this.sock.Error != null)
                {
                    this.EnqueueDebugReturn(DebugLevel.ERROR, "Exiting receive thread. Server: " + this.ConnectAddress + " Error: " + this.sock.Error);
                    this.HandleException(StatusCode.ExceptionOnConnect);
                    return;
                }

                this.State = PhotonSocketState.Connected;
                this.peerBase.OnConnect();
            }
            catch (SecurityException se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ConnectAddress + "' failed: " + se.ToString());
                }

                this.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception se)
            {
                if (this.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    this.Listener.DebugReturn(DebugLevel.ERROR, "Connect() to '" + this.ConnectAddress + "' failed: " + se.ToString());
                }

                this.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }

            Thread run = new Thread(new ThreadStart(this.ReceiveLoop));

            run.Name         = "photon receive thread";
            run.IsBackground = true;
            run.Start();
        }
Example #9
0
        internal void DnsAndConnect()
        {
            IPAddress iPAddress = null;

            try
            {
                iPAddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
                bool flag = iPAddress == null;
                if (flag)
                {
                    throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
                }
                object obj = this.syncer;
                lock (obj)
                {
                    bool flag2 = base.State == PhotonSocketState.Disconnecting || base.State == PhotonSocketState.Disconnected;
                    if (flag2)
                    {
                        return;
                    }
                    this.sock = new Socket(iPAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.Connect(iPAddress, base.ServerPort);
                    base.AddressResolvedAsIpv6 = base.IsIpv6SimpleCheck(iPAddress);
                    base.State = PhotonSocketState.Connected;
                    this.peerBase.OnConnect();
                }
            }
            catch (SecurityException ex)
            {
                bool flag3 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                if (flag3)
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (iPAddress == null) ? "" : iPAddress.AddressFamily.ToString(),
                        ") failed: ",
                        ex.ToString()
                    }));
                }
                base.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception ex2)
            {
                bool flag4 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                if (flag4)
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (iPAddress == null) ? "" : iPAddress.AddressFamily.ToString(),
                        ") failed: ",
                        ex2.ToString()
                    }));
                }
                base.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }
            new Thread(new ThreadStart(this.ReceiveLoop))
            {
                Name         = "photon receive thread",
                IsBackground = true
            }.Start();
        }
Example #10
0
        internal void DnsAndConnect()
        {
            IPAddress ipaddress = null;

            try
            {
                ipaddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
                bool flag = ipaddress == null;
                if (flag)
                {
                    throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
                }
                object obj = this.syncer;
                lock (obj)
                {
                    bool flag2 = base.State == PhotonSocketState.Disconnecting || base.State == PhotonSocketState.Disconnected;
                    if (flag2)
                    {
                        return;
                    }
                    bool flag3 = ipaddress.AddressFamily != AddressFamily.InterNetwork && ipaddress.AddressFamily != AddressFamily.InterNetworkV6;
                    if (flag3)
                    {
                        throw new ArgumentException(string.Concat(new object[]
                        {
                            "AddressFamily '",
                            ipaddress.AddressFamily,
                            "' not supported. Address: ",
                            base.ServerAddress
                        }));
                    }
                    this.sock = new Socket(ipaddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.Connect(ipaddress, base.ServerPort);
                    base.AddressResolvedAsIpv6 = base.IsIpv6SimpleCheck(ipaddress);
                    base.State = PhotonSocketState.Connected;
                    this.peerBase.OnConnect();
                }
            }
            catch (SecurityException ex)
            {
                bool flag4 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                if (flag4)
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (ipaddress == null) ? "" : ipaddress.AddressFamily.ToString(),
                        ") failed: ",
                        ex.ToString()
                    }));
                }
                base.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception ex2)
            {
                bool flag5 = base.ReportDebugOfLevel(DebugLevel.ERROR);
                if (flag5)
                {
                    base.Listener.DebugReturn(DebugLevel.ERROR, string.Concat(new string[]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        (ipaddress == null) ? "" : ipaddress.AddressFamily.ToString(),
                        ") failed: ",
                        ex2.ToString()
                    }));
                }
                base.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }
            this.StartReceive();
        }
Example #11
0
        internal void DnsAndConnect()
        {
            IPAddress     iPAddress = null;
            AddressFamily addressFamily;

            try
            {
                iPAddress = IPhotonSocket.GetIpAddress(base.ServerAddress);
                if (iPAddress == null)
                {
                    throw new ArgumentException("Invalid IPAddress. Address: " + base.ServerAddress);
                }
                object obj = this.syncer;
                lock (obj)
                {
                    if (base.State != PhotonSocketState.Disconnecting && base.State != 0)
                    {
                        this.sock = new Socket(iPAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                        this.sock.Connect(iPAddress, base.ServerPort);
                        base.AddressResolvedAsIpv6 = base.IsIpv6SimpleCheck(iPAddress);
                        base.State = PhotonSocketState.Connected;
                        base.peerBase.OnConnect();
                        goto end_IL_003d;
                    }
                    return;

                    end_IL_003d :;
                }
            }
            catch (SecurityException ex)
            {
                if (base.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    IPhotonPeerListener listener = base.Listener;
                    string[]            obj2     = new string[6]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        null,
                        null,
                        null
                    };
                    object obj3;
                    if (iPAddress != null)
                    {
                        addressFamily = iPAddress.AddressFamily;
                        obj3          = addressFamily.ToString();
                    }
                    else
                    {
                        obj3 = "";
                    }
                    obj2[3] = (string)obj3;
                    obj2[4] = ") failed: ";
                    obj2[5] = ex.ToString();
                    listener.DebugReturn(DebugLevel.ERROR, string.Concat(obj2));
                }
                base.HandleException(StatusCode.SecurityExceptionOnConnect);
                return;
            }
            catch (Exception ex2)
            {
                if (base.ReportDebugOfLevel(DebugLevel.ERROR))
                {
                    IPhotonPeerListener listener2 = base.Listener;
                    string[]            obj4      = new string[6]
                    {
                        "Connect() to '",
                        base.ServerAddress,
                        "' (",
                        null,
                        null,
                        null
                    };
                    object obj5;
                    if (iPAddress != null)
                    {
                        addressFamily = iPAddress.AddressFamily;
                        obj5          = addressFamily.ToString();
                    }
                    else
                    {
                        obj5 = "";
                    }
                    obj4[3] = (string)obj5;
                    obj4[4] = ") failed: ";
                    obj4[5] = ex2.ToString();
                    listener2.DebugReturn(DebugLevel.ERROR, string.Concat(obj4));
                }
                base.HandleException(StatusCode.ExceptionOnConnect);
                return;
            }
            Thread thread = new Thread(this.ReceiveLoop);

            thread.IsBackground = true;
            thread.Start();
        }