Exemplo n.º 1
0
    public int Connect(string address, int port)
    {
        IPAddress[] ipAddresses;
        try
        {
            ipAddresses = Dns.GetHostAddresses(address);
        }
        catch (System.Exception e)
        {
            GameDebug.Log("Unable to resolve " + address + ". " + e.Message);
            return(0);
        }

        if (ipAddresses.Length < 1)
        {
            GameDebug.Log("Unable to resolve " + address + ". Host not found");
            return(0);
        }

        // TODO (petera) do we want to do round-robin?
        var ip = ipAddresses[0].ToString();

        byte error;

        if (UnityEngine.Debug.isDebugBuild && m_isNetworkSimuationActive)
        {
            var simulationConfig = new ConnectionSimulatorConfig(48, 50, 48, 50, 10);
            return(NetworkTransport.ConnectWithSimulator(m_HostId, ip, port, 0, out error, simulationConfig));
        }
        else
        {
            return(NetworkTransport.Connect(m_HostId, ip, port, 0, out error));
        }
    }
Exemplo n.º 2
0
 public static int ConnectWithSimulator(int hostId, string serverAddress, int serverPort, string relayAddress, int relayPort, int exceptionConnectionId, out byte error, ConnectionSimulatorConfig conf)
 {
     isClient = true;
     RelayTransport.address = serverAddress;
     RelayTransport.port    = (ushort)serverPort;
     relayConnectionId      = NetworkTransport.ConnectWithSimulator(hostId, relayAddress, relayPort, exceptionConnectionId, out error, conf); // Requests connection
     return(relayConnectionId);
 }
Exemplo n.º 3
0
    private void Start()
    {
        byte error;
        //connectionId = NetworkTransport.Connect(socketId, serverAddr, serverPort, 0, out error);
        ConnectionSimulatorConfig csc = new ConnectionSimulatorConfig(160, 200, 160, 200, 0.15f);

        connectionId = NetworkTransport.ConnectWithSimulator(socketId, serverAddr, serverPort, 0, out error, csc);
        Debug.Log("Connected to server. ConnectionId: " + connectionId + " error:" + (int)error);
    }
Exemplo n.º 4
0
    public int ConnectWithSimulator(IP2PAddress address, out byte error, ConnectionSimulatorConfig config)
    {
        P2PAddressUnet p2PAddressUnet = address as P2PAddressUnet;

        if (p2PAddressUnet != null)
        {
            return(NetworkTransport.ConnectWithSimulator((int)P2PSession.Instance.LocalPeer.GetLocalHostId(), p2PAddressUnet.m_IP, p2PAddressUnet.m_Port, 0, out error, config));
        }
        Debug.LogError(string.Format("Using invalid IP2PAddress type {0}", address.GetType()));
        error = 0;
        return(-1);
    }
Exemplo n.º 5
0
        public override void Connect(string ipAddress, int serverPort)
        {
            byte num;

            if (this._isDelaySimulator)
            {
                this._hostID     = NetworkTransport.AddHostWithSimulator(this._ht, 0x3e8, 0x5dc);
                this._selfConnID = NetworkTransport.ConnectWithSimulator(this._hostID, ipAddress, serverPort, 0, out num, this._simulatorConfig);
            }
            else
            {
                this._hostID     = NetworkTransport.AddHost(this._ht);
                this._selfConnID = NetworkTransport.Connect(this._hostID, ipAddress, serverPort, 0, out num);
            }
            if (num != 0)
            {
                throw new UnityException("bad connection : " + ((NetworkError)num));
            }
            this._state = MPPeer.PeerState.ClientConnecting;
            this._clientConnectState = ClientConnectState.Idle;
        }
Exemplo n.º 6
0
        private void InitializeClient(string serverIP, HostTopology topology)
        {
            if (m_Settings.m_SimulateNetworking)
            {
                m_HostID = NetworkTransport.AddHostWithSimulator(topology, m_Settings.m_MinLatency, m_Settings.m_MaxLatency, 0);
            }
            else
            {
                m_HostID = NetworkTransport.AddHost(topology, 0);
            }

            byte error;

            if (m_Settings.m_SimulateNetworking)
            {
                int min = m_Settings.m_MinLatency;

                int avg = (m_Settings.m_MinLatency + m_Settings.m_MaxLatency) / 2;

                ConnectionSimulatorConfig conf = new ConnectionSimulatorConfig(min, avg, min, avg, m_Settings.m_PacketLoss);

                ConnectionID = NetworkTransport.ConnectWithSimulator(m_HostID, serverIP, m_Settings.m_Port, 0, out error, conf);
            }
            else
            {
                ConnectionID = NetworkTransport.Connect(m_HostID, serverIP, m_Settings.m_Port, 0, out error);
            }

            DebugLog(string.Format("Connecting to {0}...", serverIP));

            if ((NetworkError)error != NetworkError.Ok)
            {
                DebugLog("Connection failed: " + (NetworkError)error);
                return;
            }

            RegisterHandlers();
        }
Exemplo n.º 7
0
        public void Connect(string address, int port)
        {
            byte error;

            bool simulateLatency = false;

            if (simulateLatency)
            {
                ConnectionSimulatorConfig simConfig = new ConnectionSimulatorConfig(50, 50, 50, 50, 0);
                connectionID = NetworkTransport.ConnectWithSimulator(hostID, address, port, 0, out error, simConfig);
            }
            else
            {
                connectionID = NetworkTransport.Connect(hostID, address, port, 0, out error);
            }

            NetworkError networkError = (NetworkError)error;

            if (networkError != NetworkError.Ok)
            {
                Debug.LogError(networkError);
            }
        }
Exemplo n.º 8
0
 public int ConnectWithSimulator(int hostId, string address, int port, int specialConnectionId, out byte error, ConnectionSimulatorConfig conf)
 {
     return(NetworkTransport.ConnectWithSimulator(hostId, address, port, specialConnectionId, out error, conf));
 }