Ejemplo n.º 1
0
        public override void ClientConnect(string address)
        {
            if (clientConnection != null)
            {
                Debug.LogWarning("KCP: client already connected!");
                return;
            }

            clientConnection = new KcpClientConnection();
            // setup events
            clientConnection.OnConnected += () =>
            {
                Debug.LogWarning($"KCP->Mirror OnClientConnected");
                OnClientConnected.Invoke();
            };
            clientConnection.OnData += (message) =>
            {
                //Debug.LogWarning($"KCP->Mirror OnClientData({BitConverter.ToString(message.Array, message.Offset, message.Count)})");
                OnClientDataReceived.Invoke(message);
            };
            clientConnection.OnDisconnected += () =>
            {
                Debug.LogWarning($"KCP->Mirror OnClientDisconnected");
                OnClientDisconnected.Invoke();
            };

            // connect
            clientConnection.Connect(address, Port);

            // configure connection for max scale
            ConfigureKcpConnection(clientConnection);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Connect to a server located at a provided uri
        /// </summary>
        /// <param name="uri">address of the server to connect to</param>
        /// <returns>The connection to the server</returns>
        /// <exception>If connection cannot be established</exception>
        public override async UniTask <IConnection> ConnectAsync(Uri uri)
        {
            var client = new KcpClientConnection(delayMode)
            {
                HashCashBits = HashCashBits
            };

            ushort port = (ushort)(uri.IsDefaultPort? Port : uri.Port);

            await client.ConnectAsync(uri.Host, port);

            return(client);
        }
Ejemplo n.º 3
0
 public override void ClientDisconnect()
 {
     clientConnection?.Disconnect();
     clientConnection = null;
 }