UnityEngine.Networking.NetworkTransport.ConnectEndPoint C# (CSharp) Method

ConnectEndPoint() public static method

public static ConnectEndPoint ( int hostId, EndPoint endPoint, int exceptionConnectionId, byte &error ) : int
hostId int
endPoint System.Net.EndPoint
exceptionConnectionId int
error byte
return int
        public static int ConnectEndPoint(int hostId, EndPoint endPoint, int exceptionConnectionId, out byte error)
        {
            error = 0;
            byte[] buffer = new byte[] { 0x5f, 0x24, 0x13, 0xf6 };
            if (endPoint == null)
            {
                throw new NullReferenceException("Null EndPoint provided");
            }
            if (((endPoint.GetType().FullName != "UnityEngine.XboxOne.XboxOneEndPoint") && (endPoint.GetType().FullName != "UnityEngine.PS4.SceEndPoint")) && (endPoint.GetType().FullName != "UnityEngine.PSVita.SceEndPoint"))
            {
                throw new ArgumentException("Endpoint of type XboxOneEndPoint or SceEndPoint  required");
            }
            if (endPoint.GetType().FullName == "UnityEngine.XboxOne.XboxOneEndPoint")
            {
                EndPoint point = endPoint;
                if (point.AddressFamily != AddressFamily.InterNetworkV6)
                {
                    throw new ArgumentException("XboxOneEndPoint has an invalid family");
                }
                SocketAddress address = point.Serialize();
                if (address.Size != 14)
                {
                    throw new ArgumentException("XboxOneEndPoint has an invalid size");
                }
                if ((address[0] != 0) || (address[1] != 0))
                {
                    throw new ArgumentException("XboxOneEndPoint has an invalid family signature");
                }
                if (((address[2] != buffer[0]) || (address[3] != buffer[1])) || ((address[4] != buffer[2]) || (address[5] != buffer[3])))
                {
                    throw new ArgumentException("XboxOneEndPoint has an invalid signature");
                }
                byte[] buffer2 = new byte[8];
                for (int j = 0; j < buffer2.Length; j++)
                {
                    buffer2[j] = address[6 + j];
                }
                IntPtr ptr = new IntPtr(BitConverter.ToInt64(buffer2, 0));
                if (ptr == IntPtr.Zero)
                {
                    throw new ArgumentException("XboxOneEndPoint has an invalid SOCKET_STORAGE pointer");
                }
                byte[] buffer3 = new byte[2];
                Marshal.Copy(ptr, buffer3, 0, buffer3.Length);
                AddressFamily family = (AddressFamily) ((buffer3[1] << 8) + buffer3[0]);
                if (family != AddressFamily.InterNetworkV6)
                {
                    throw new ArgumentException("XboxOneEndPoint has corrupt or invalid SOCKET_STORAGE pointer");
                }
                return Internal_ConnectEndPoint(hostId, ptr, 0x80, exceptionConnectionId, out error);
            }
            SocketAddress address2 = endPoint.Serialize();
            if (address2.Size != 0x10)
            {
                throw new ArgumentException("EndPoint has an invalid size");
            }
            if (address2[0] != address2.Size)
            {
                throw new ArgumentException("EndPoint has an invalid size value");
            }
            if (address2[1] != 2)
            {
                throw new ArgumentException("EndPoint has an invalid family value");
            }
            byte[] source = new byte[0x10];
            for (int i = 0; i < source.Length; i++)
            {
                source[i] = address2[i];
            }
            IntPtr destination = Marshal.AllocHGlobal(source.Length);
            Marshal.Copy(source, 0, destination, source.Length);
            int num4 = Internal_ConnectEndPoint(hostId, destination, 0x10, exceptionConnectionId, out error);
            Marshal.FreeHGlobal(destination);
            return num4;
        }

Usage Example

示例#1
0
        public void Connect(EndPoint secureTunnelEndPoint)
        {
            PrepareForConnect();
            if (LogFilter.logDebug)
            {
                Debug.Log("Client Connect to remoteSockAddr");
            }
            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: null endpoint passed in");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            if (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork && secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            string fullName = secureTunnelEndPoint.GetType().FullName;

            if (fullName == "System.Net.IPEndPoint")
            {
                IPEndPoint iPEndPoint = (IPEndPoint)secureTunnelEndPoint;
                Connect(iPEndPoint.Address.ToString(), iPEndPoint.Port);
                return;
            }
            if (fullName != "UnityEngine.XboxOne.XboxOneEndPoint")
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint)");
                }
                m_AsyncConnect = ConnectState.Failed;
                return;
            }
            byte error = 0;

            m_RemoteEndPoint = secureTunnelEndPoint;
            m_AsyncConnect   = ConnectState.Connecting;
            try
            {
                m_ClientConnectionId = NetworkTransport.ConnectEndPoint(m_ClientId, m_RemoteEndPoint, 0, out error);
            }
            catch (Exception arg)
            {
                Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + arg);
            }
            if (m_ClientConnectionId == 0 && LogFilter.logError)
            {
                Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")");
            }
            m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
            m_Connection.SetHandlers(m_MessageHandlers);
            m_Connection.Initialize(m_ServerIp, m_ClientId, m_ClientConnectionId, m_HostTopology);
        }
All Usage Examples Of UnityEngine.Networking.NetworkTransport::ConnectEndPoint