Exemplo n.º 1
0
        /// <summary>
        /// Default behaviour is to accept every connection
        /// </summary>
        public virtual void OnConnecting(Connection connection, ConnectionInfo data)
        {
            connection.Accept();
            Connecting.Add(connection);

            SteamNetworkingSockets.Internal.SetConnectionPollGroup(connection, pollGroup);
        }
Exemplo n.º 2
0
        public void ListenAndAcceptTest()
        {
            IPAddress ipAddress = Util.GetLocalIPAddress();

            if (ipAddress != null)
            {
                IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

                Connection localConnection = new Connection();
                localConnection.Listen(localEndPoint);

                Socket remoteSender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                remoteSender.Connect(localEndPoint);

                System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
                var receiver = localConnection.Accept();
                var elapsed  = sw.Elapsed;

                remoteSender.Close();
                localConnection.Close();

                System.Diagnostics.Debug.WriteLine("Time took to accept connection " + elapsed);
                Assert.IsTrue(elapsed.Seconds < 1, "New connection is not accepted in timely manner fashon.");
            }
            else
            {
                Assert.Fail("Can't obtain IP address.");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Default behaviour is to accept every connection
 /// </summary>
 public virtual void OnConnecting(Connection connection, ConnectionInfo info)
 {
     if (Interface != null)
     {
         Interface.OnConnecting(connection, info);
     }
     else
     {
         connection.Accept();
     }
 }
Exemplo n.º 4
0
 public void DoWork()
 {
     while (true)
     {
         if (conn.CanRead())
         {
             Connection newConn = conn.Accept();
             lock (newConnQueue)
             {
                 newConnQueue.Enqueue(newConn);
             }
         }
         Thread.Sleep(1);
     }
 }
Exemplo n.º 5
0
        private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info)
        {
            ulong clientSteamID = info.Identity.SteamId;

            if (info.State == ConnectionState.Connecting)
            {
                if (connToMirrorID.Count >= maxConnections)
                {
                    Debug.Log($"Incoming connection {clientSteamID} would exceed max connection count. Rejecting.");
                    conn.Close(false, 0, "Max Connection Count");
                    return;
                }

                Result res;

                if ((res = conn.Accept()) == Result.OK)
                {
                    Debug.Log($"Accepting connection {clientSteamID}");
                }
                else
                {
                    Debug.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}");
                }
            }
            else if (info.State == ConnectionState.Connected)
            {
                int connectionId = nextConnectionID++;
                connToMirrorID.Add(conn, connectionId);
                steamIDToMirrorID.Add(clientSteamID, connectionId);
                OnConnected.Invoke(connectionId);
                Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}");
            }
            else if (info.State == ConnectionState.ClosedByPeer)
            {
                if (connToMirrorID.TryGetValue(conn, out int connId))
                {
                    InternalDisconnect(connId, conn);
                }
            }
            else
            {
                Debug.Log($"Connection {clientSteamID} state changed: {info.State.ToString()}");
            }
        }
Exemplo n.º 6
0
        public void Receive_Less_Then_ReadBufferSize_Bytes_Test()
        {
            IPAddress ipAddress = Util.GetLocalIPAddress();

            if (ipAddress != null)
            {
                IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

                Connection localConnection = new Connection();
                localConnection.Listen(localEndPoint);

                byte[] expectedData = new byte[localConnection.ReadBufferSize - 1];
                for (int i = 0; i < expectedData.Length; i++)
                {
                    expectedData[i] = (byte)(i % byte.MaxValue);
                }

                new Task(() =>
                {
                    Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    System.Threading.Thread.Sleep(1000);
                    sender.Connect(localEndPoint);
                    sender.Send(expectedData);
                }).Start();

                var    receiver     = localConnection.Accept();
                byte[] receivedData = receiver.Receive();

                localConnection.Close();

                Assert.IsTrue(expectedData.SequenceEqual(receivedData), "Data are not the same.");
            }
            else
            {
                Assert.Fail("Can't obtain IP address.");
            }
        }
 public virtual void OnConnecting(Connection connection, ConnectionInfo data)
 {
     connection.Accept();
     this.Connecting.Add(connection);
 }
 public void OnConnecting(Connection connection, ConnectionInfo data)
 {
     connection.Accept();
     Debug.Log($"{data.Identity} is connecting");
 }