public void Connect(string address, ushort port, bool noDelay, uint interval, int fastResend = 0, bool congestionWindow = true, uint sendWindowSize = Kcp.WND_SND, uint receiveWindowSize = Kcp.WND_RCV, int timeout = KcpConnection.DEFAULT_TIMEOUT)
        {
            if (connected)
            {
                Log.Warning("KCP: client already connected!");
                return;
            }

            connection = new KcpClientConnection();

            // setup events
            connection.OnAuthenticated = () =>
            {
                Log.Info($"KCP: OnClientConnected");
                connected = true;
                OnConnected.Invoke();
            };
            connection.OnData = (message) =>
            {
                //Log.Debug($"KCP: OnClientData({BitConverter.ToString(message.Array, message.Offset, message.Count)})");
                OnData.Invoke(message);
            };
            connection.OnDisconnected = () =>
            {
                Log.Info($"KCP: OnClientDisconnected");
                connected  = false;
                connection = null;
                OnDisconnected.Invoke();
            };

            // connect
            connection.Connect(address, port, noDelay, interval, fastResend, congestionWindow, sendWindowSize, receiveWindowSize, timeout);
        }
Beispiel #2
0
        public void Connect(string address,
                            ushort port,
                            bool noDelay,
                            uint interval,
                            int fastResend         = 0,
                            bool congestionWindow  = true,
                            uint sendWindowSize    = Kcp.WND_SND,
                            uint receiveWindowSize = Kcp.WND_RCV,
                            int timeout            = KcpConnection.DEFAULT_TIMEOUT,
                            uint maxRetransmits    = Kcp.DEADLINK,
                            bool maximizeSendReceiveBuffersToOSLimit = false)
        {
            if (connected)
            {
                Log.Warning("KCP: client already connected!");
                return;
            }

            // create connection
            connection = CreateConnection();

            // setup events
            connection.OnAuthenticated = () =>
            {
                Log.Info($"KCP: OnClientConnected");
                connected = true;
                OnConnected();
            };
            connection.OnData = (message, channel) =>
            {
                //Log.Debug($"KCP: OnClientData({BitConverter.ToString(message.Array, message.Offset, message.Count)})");
                OnData(message, channel);
            };
            connection.OnDisconnected = () =>
            {
                Log.Info($"KCP: OnClientDisconnected");
                connected  = false;
                connection = null;
                OnDisconnected();
            };
            connection.OnError = (error, reason) =>
            {
                OnError(error, reason);
            };

            // connect
            connection.Connect(address,
                               port,
                               noDelay,
                               interval,
                               fastResend,
                               congestionWindow,
                               sendWindowSize,
                               receiveWindowSize,
                               timeout,
                               maxRetransmits,
                               maximizeSendReceiveBuffersToOSLimit);
        }
Beispiel #3
0
        public void Connect(string address, ushort port, bool noDelay, uint interval, int fastResend = 0, bool congestionWindow = true, uint sendWindowSize = Kcp.WND_SND, uint receiveWindowSize = Kcp.WND_RCV)
        {
            if (connected)
            {
                Log.Warning("KCP: client already connected!");
                return;
            }

            connection = new KcpClientConnection();

            // setup events
            connection.OnAuthenticated = () =>
            {
                Log.Info($"KCP: OnClientConnected");
                connected = true;
                OnConnected.Invoke();
            };
            connection.OnData = (message) =>
            {
                //Log.Debug($"KCP: OnClientData({BitConverter.ToString(message.Array, message.Offset, message.Count)})");
                OnData.Invoke(message);
            };
            connection.OnDisconnected = () =>
            {
                Log.Info($"KCP: OnClientDisconnected");
                connected  = false;
                connection = null;
                OnDisconnected.Invoke();
            };

            // setup OnCheckEnabled to safely support Mirror
            // scene changes (see comments in Awake() above)
            connection.OnCheckEnabled = OnCheckEnabled;

            // connect
            connection.Connect(address, port, noDelay, interval, fastResend, congestionWindow, sendWindowSize, receiveWindowSize);
        }