public void Connect(string address)
    {
        Init();

        NetworkEndPoint endpoint;

        if (NetworkEndPoint.TryParse(address, 9000, out endpoint))
        {
            Debug.LogError("Could Not Parse Address");
        }

        connection = networkDriver.Connect(endpoint);
    }
Beispiel #2
0
        public void CreateAndConnect_NetworkConnection_ToRemoteEndPoint()
        {
            var connection = Driver.Connect(RemoteDriver.LocalEndPoint());

            Assert.That(connection.IsCreated);
            Driver.ScheduleUpdate().Complete();

            RemoteDriver.ScheduleUpdate().Complete();
            Assert.That(RemoteDriver.Accept().IsCreated);

            Driver.ScheduleUpdate().Complete();
            DataStreamReader reader;

            Assert.That(connection.PopEvent(Driver, out reader) == NetworkEvent.Type.Connect);
        }
Beispiel #3
0
        public void ShouldAcceptConnection()
        {
            Server.Instance.Init(new ushort[] { 9099 }, 100, true, false);
            var serverDriver = new NetworkDriver(new IPCNetworkInterface(), new NetworkDataStreamParameter {
                size = 64
            });

            Server.Instance.Start(serverDriver);

            // send out connection request
            var clientDriver = new NetworkDriver(new IPCNetworkInterface(), new NetworkDataStreamParameter {
                size = 64
            });
            NetworkConnection networkConnection = clientDriver.Connect(serverDriver.LocalEndPoint());

            Assert.True(networkConnection != default);
            clientDriver.ScheduleUpdate().Complete();

            var numberOfConnectedClients = 0;
            var onClientConnected        = new Server.ConnectionDelegate(id => numberOfConnectedClients++);

            Server.Instance.ClientConnected += onClientConnected;
            Server.Instance.Tick();
            Assert.AreEqual(1, numberOfConnectedClients);
            Server.Instance.ClientConnected -= onClientConnected;

            if (clientDriver.IsCreated)
            {
                clientDriver.Dispose();
            }
        }
Beispiel #4
0
        public void DisconnectByMaxConnectionAttempts()
        {
            using (var host = new LocalDriverHelper(default(NetworkEndPoint)))
                using (var client = new NetworkDriver(new IPCNetworkInterface(), new NetworkConfigParameter {
                    maxConnectAttempts = 1, fixedFrameTimeMS = 10, connectTimeoutMS = 25
                }))
                {
                    host.Host();
                    var popEvent = NetworkEvent.Type.Empty;
                    var c        = client.Connect(host.EndPoint);
                    client.ScheduleUpdate().Complete();

                    byte reason = 0;
                    var  reader = default(DataStreamReader);
                    for (int frm = 0; frm < 10; ++frm)
                    {
                        if ((popEvent = client.PopEvent(out var id, out reader)) != NetworkEvent.Type.Empty)
                        {
                            reason = (reader.IsCreated && reader.Length > 0) ? reason = reader.ReadByte() : (byte)0;
                            break;
                        }
                        client.ScheduleUpdate().Complete();
                    }
                    Assert.AreEqual(NetworkEvent.Type.Disconnect, popEvent);
                    Assert.AreEqual((byte)DisconnectReason.MaxConnectionAttempts, reason);
                }
        }
Beispiel #5
0
        public void DisconnectFromARemoteEndPoint()
        {
            using (var host = new LocalDriverHelper(default(NetworkEndPoint)))
            {
                host.Host();
                var driver = new NetworkDriver(new IPCNetworkInterface(), new NetworkDataStreamParameter {
                    size = 64
                });

                // Need to be connected in order to be able to send a disconnect packet.
                NetworkConnection connectionId = driver.Connect(host.EndPoint);
                Assert.True(connectionId != default(NetworkConnection));
                driver.ScheduleUpdate().Complete();

                var local = driver.LocalEndPoint();
                host.Assert_GotConnectionRequest(local, true);

                NetworkConnection con;
                DataStreamReader  slice;
                // Pump so we get the accept message back.
                driver.ScheduleUpdate().Complete();
                Assert.AreEqual(NetworkEvent.Type.Connect, driver.PopEvent(out con, out slice));
                driver.Disconnect(connectionId);
                driver.ScheduleUpdate().Complete();

                host.Assert_GotDisconnectionRequest(local);

                driver.Dispose();
            }
        }
Beispiel #6
0
    public static void Connect()
    {
        Debug.Log("Attempting to connect to server.");
        var endpoint = NetworkEndPoint.Parse(ADDRESS, PORT);

        Connection = Driver.Connect(endpoint);
    }
Beispiel #7
0
        public void SetupServerAndClientAndConnectThem(int bufferSize)
        {
            //setup server
            server_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            NetworkEndPoint server_endpoint = NetworkEndPoint.LoopbackIpv4;

            server_endpoint.Port = 1337;
            server_driver.Bind(server_endpoint);
            server_driver.Listen();

            //setup client
            client_driver = NetworkDriver.Create(new NetworkDataStreamParameter {
                size = bufferSize
            });
            clientToServerConnection = client_driver.Connect(server_endpoint);

            //update drivers
            client_driver.ScheduleUpdate().Complete();
            server_driver.ScheduleUpdate().Complete();

            //accept connection
            connectionToClient = server_driver.Accept();

            server_driver.ScheduleUpdate().Complete();
            ev = server_driver.PopEventForConnection(connectionToClient, out stream);
            Assert.IsTrue(ev == NetworkEvent.Type.Empty, "Not empty NetworkEvent on the server appeared");

            client_driver.ScheduleUpdate().Complete();
            ev = clientToServerConnection.PopEvent(client_driver, out stream);
            Assert.IsTrue(ev == NetworkEvent.Type.Connect, "NetworkEvent should have Type.Connect on the client");
        }
Beispiel #8
0
        public void ClientStart(string ipAdress)
        {
            // create the network connection
            networkDriver = NetworkDriver.Create();
            connection    = default;
            var endpoint = NetworkEndPoint.LoopbackIpv4;

            endpoint.Port = 9000;

            if (ipAdress != "")
            {
                endpoint = NetworkEndPoint.Parse(ipAdress, 9000);
            }

            connection = networkDriver.Connect(endpoint);

            // Instatiate & Finds
            messagesQueue = new Queue <MessageConnection>();
            for (int i = 0; i < ClientCallbacks.Length; i++)
            {
                ClientCallbacks[i] = new MessageEvent(); // Instantiate all Message Type events.
            }

            LobbyManager = GameObject.FindGameObjectWithTag("GameController").GetComponent <LobbyManager>();
            AddProtocolEventListeners();
            doneInitializing = true;
        }
Beispiel #9
0
        public void Accept()
        {
            Driver.Bind(NetworkEndPoint.LoopbackIpv4);
            Driver.Listen();
            Assert.That(Driver.Listening);

            // create connection to test to connect.
            /*var remote =*/ RemoteDriver.Connect(Driver.LocalEndPoint());

            NetworkConnection id;
            DataStreamReader  reader;
            const int         maximumIterations = 10;
            int  count     = 0;
            bool connected = false;

            while (count++ < maximumIterations)
            {
                // Clear pending events
                Driver.PopEvent(out id, out reader);
                RemoteDriver.PopEvent(out id, out reader);

                Driver.ScheduleUpdate().Complete();
                RemoteDriver.ScheduleUpdate().Complete();
                var connection = Driver.Accept();
                if (connection != default(NetworkConnection))
                {
                    connected = true;
                }
            }

            Assert.That(connected);
        }
Beispiel #10
0
        public void DisconnectByRemote()
        {
            using (var host = new LocalDriverHelper(default(NetworkEndPoint)))
                using (var client = new NetworkDriver(new IPCNetworkInterface()))
                {
                    host.Host();
                    var popEvent = NetworkEvent.Type.Empty;
                    var c        = client.Connect(host.EndPoint);

                    client.ScheduleUpdate().Complete();
                    host.Assert_GotConnectionRequest(client.LocalEndPoint(), true);

                    byte             reason = 0;
                    DataStreamReader reader;
                    for (int frm = 0; frm < 10; ++frm)
                    {
                        if (c.GetState(client) == NetworkConnection.State.Connected)
                        {
                            c.Disconnect(client);
                        }

                        if ((popEvent = host.m_LocalDriver.PopEvent(out var id, out reader)) != NetworkEvent.Type.Empty)
                        {
                            reason = (reader.IsCreated && reader.Length > 0) ? reason = reader.ReadByte() : (byte)0;
                            break;
                        }
                        host.Update();
                        client.ScheduleUpdate().Complete();
                    }
                    Assert.AreEqual(NetworkEvent.Type.Disconnect, popEvent);
                    Assert.AreEqual((byte)DisconnectReason.ClosedByRemote, reason);
                }
        }
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
    }
Beispiel #12
0
    ///-----------------------------Events-----------------------------------//

    // fired on start of client program
    void Start()
    {
        //console = GameObject.Find("UI").GetComponent<UI_Handler>();
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
    }
    void FixedUpdate()
    {
        // Update the ping client UI with the ping statistics computed by teh job scheduled previous frame since that
        // is now guaranteed to have completed
        PingClientUIBehaviour.UpdateStats(m_numPingsSent, m_lastPingTime);

        // Update the NetworkDriver. It schedules a job so we must wait for that job with Complete
        m_ClientDriver.ScheduleUpdate().Complete();

        // If the client ui indicates we should be sending pings but we do not have an active connection we create one
        if (PingClientUIBehaviour.ServerEndPoint.IsValid && !m_clientToServerConnection.IsCreated)
        {
            m_clientToServerConnection = m_ClientDriver.Connect(PingClientUIBehaviour.ServerEndPoint);
        }
        // If the client ui indicates we should not be sending pings but we do have a connection we close that connection
        if (!PingClientUIBehaviour.ServerEndPoint.IsValid && m_clientToServerConnection.IsCreated)
        {
            m_clientToServerConnection.Disconnect(m_ClientDriver);
            m_clientToServerConnection = default(NetworkConnection);
        }

        DataStreamReader strm;

        NetworkEvent.Type cmd;
        // Process all events on the connection. If the connection is invalid it will return Empty immediately
        while ((cmd = m_clientToServerConnection.PopEvent(m_ClientDriver, out strm)) != NetworkEvent.Type.Empty)
        {
            if (cmd == NetworkEvent.Type.Connect)
            {
                // When we get the connect message we can start sending data to the server
                // Set the ping id to a sequence number for the new ping we are about to send
                m_pendingPing = new PendingPing {
                    id = m_numPingsSent, time = Time.fixedTime
                };
                // Create a 4 byte data stream which we can store our ping sequence number in
                if (m_ClientDriver.BeginSend(m_clientToServerConnection, out var pingData) == 0)
                {
                    pingData.WriteInt(m_numPingsSent);
                    m_ClientDriver.EndSend(pingData);
                }
                // Update the number of sent pings
                ++m_numPingsSent;
            }
            else if (cmd == NetworkEvent.Type.Data)
            {
                // When the pong message is received we calculate the ping time and disconnect
                m_lastPingTime = (int)((Time.fixedTime - m_pendingPing.time) * 1000);
                m_clientToServerConnection.Disconnect(m_ClientDriver);
                m_clientToServerConnection = default(NetworkConnection);
            }
            else if (cmd == NetworkEvent.Type.Disconnect)
            {
                // If the server disconnected us we clear out connection
                m_clientToServerConnection = default(NetworkConnection);
            }
        }
    }
Beispiel #14
0
    void Start()
    {
        m_Driver                               = NetworkDriver.Create();
        m_Connection                           = default(NetworkConnection);
        serverIP                               = "3.12.76.48"//"127.0.0.1";
                                  var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
    }
    //

    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
        ID           = UnityEngine.Random.value.ToString();
    }
Beispiel #16
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
        ClientsList  = new Dictionary <string, GameObject>();
    }
    public void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.LoopbackIpv4;

        endpoint.Port = port;
        m_Connection  = m_Driver.Connect(endpoint);
    }
    // Use this for initialization
    private void Start()
    {
        networkDriver = NetworkDriver.Create();
        connection    = default;

        clientMessagesQueue = new Queue <MessageHeader>();

        for (int i = 0; i < ClientCallbacks.Length; i++)
        {
            ClientCallbacks[i] = new MessageEvent();
        }

        ClientCallbacks[(int)MessageHeader.MessageType.NewPlayer].AddListener(PlayerManager.Instance.NewPlayer);
        ClientCallbacks[(int)MessageHeader.MessageType.NewPlayer].AddListener(UIManager.Instance.SortingPlayerLabel);
        ClientCallbacks[(int)MessageHeader.MessageType.StartGame].AddListener(PlayerManager.Instance.SetBeginHealth);
        ClientCallbacks[(int)MessageHeader.MessageType.StartGame].AddListener(UIManager.Instance.SwitchToGamePanel);
        ClientCallbacks[(int)MessageHeader.MessageType.StartGame].AddListener(UIManager.Instance.DeletePlayerLabels);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerTurn].AddListener(UIManager.Instance.CheckTurn);
        ClientCallbacks[(int)MessageHeader.MessageType.RequestDenied].AddListener(UIManager.Instance.ShowErrorCode);
        ClientCallbacks[(int)MessageHeader.MessageType.RoomInfo].AddListener(UIManager.Instance.ShowNewRoom);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerEnterRoom].AddListener(UIManager.Instance.EnterPlayer);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerLeaveRoom].AddListener(UIManager.Instance.LeavePlayer);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerLeft].AddListener(UIManager.Instance.DisableSpawnLabel);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerLeft].AddListener(UIManager.Instance.RemovePlayer);
        ClientCallbacks[(int)MessageHeader.MessageType.HitMonster].AddListener(UIManager.Instance.ToggleAttackAnimation);
        ClientCallbacks[(int)MessageHeader.MessageType.HitByMonster].AddListener(PlayerManager.Instance.HitByMonster);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerDies].AddListener(PlayerManager.Instance.PlayerDies);
        ClientCallbacks[(int)MessageHeader.MessageType.ObtainTreasure].AddListener(UIManager.Instance.ObtainTreasure);
        ClientCallbacks[(int)MessageHeader.MessageType.PlayerDefends].AddListener(UIManager.Instance.PlayerDefend);
        ClientCallbacks[(int)MessageHeader.MessageType.EndGame].AddListener(GameManager.Instance.InsertScore);

        if (GameManager.Instance.LOCAL)
        {
            var endpoint = NetworkEndPoint.LoopbackIpv4;
            endpoint.Port = 9000;
            connection    = networkDriver.Connect(endpoint);
        }
        else
        {
            var endPoint = NetworkEndPoint.Parse(IPAdress, 9000);
            connection = networkDriver.Connect(endPoint);
        }
        TimerManager.Instance.AddTimer(StayAlive, 10);
    }
    void Start()
    {
        localDriver = NetworkDriver.Create();
        connection  = default(NetworkConnection);

        var endpoint = NetworkEndPoint.LoopbackIpv4;

        endpoint.Port = Port;
        connection    = localDriver.Connect(endpoint);
    }
Beispiel #20
0
    // Use this for initialization
    void Start()
    {
        networkDriver = NetworkDriver.Create();
        connection    = default;

        var endpoint = NetworkEndPoint.LoopbackIpv4;

        endpoint.Port = 9000;
        connection    = networkDriver.Connect(endpoint);
    }
Beispiel #21
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        playerList = new List <GameObject>();
    }
Beispiel #22
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
        sendInfo     = false;
        t            = GameObject.Find("Cube");
    }
Beispiel #23
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        serverIP     = "3.137.149.42";
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        playerIDText = player.gameObject.GetComponentInChildren <TextMeshProUGUI>();
    }
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        currentPlayers  = new Dictionary <string, GameObject>();
        latestGameState = new List <NetworkObjects.NetworkPlayer>();
    }
Beispiel #25
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
        players      = new Dictionary <string, GameObject>();

        InvokeRepeating("playerUpdate", 0.1f, 0.1f);
    }
    void Start()
    {
        dataHolder        = GetComponent <DataHolder>();
        dataHolder.client = this;

        networkDriver = NetworkDriver.Create();
        connection    = default;

        if (Tools.LOCAL)
        {
            var endpoint = NetworkEndPoint.LoopbackIpv4;
            endpoint.Port = 9000;
            connection    = networkDriver.Connect(endpoint);
        }
        else
        {
            var endpoint = NetworkEndPoint.Parse(Tools.IP, 9000);
            connection = networkDriver.Connect(endpoint);
        }
    }
Beispiel #27
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = new NativeArray <NetworkConnection>(1, Allocator.Persistent);
        m_Done       = new NativeArray <byte>(1, Allocator.Persistent);

        NetworkEndPoint endpoint = NetworkEndPoint.LoopbackIpv4;

        endpoint.Port   = 6969;
        m_Connection[0] = m_Driver.Connect(endpoint);
    }
Beispiel #28
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection    = m_Driver.Connect(endpoint);
        localPlayerList = new Dictionary <string, GameObject>();

        InvokeRepeating("HeartBeat", 1f, 1f);
    }
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        m_Players    = new List <NetworkObjects.NetworkPlayer>();
        m_cubes      = new List <GameObject>();
        m_internalID = "";
    }
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Server IP: " + serverIP + ":" + serverPort);

        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        StartCoroutine(GetMyIPAddress());
    }