Пример #1
0
        internal void DisconnectPeer(
            NetPeer peer,
            DisconnectReason reason,
            int socketErrorCode,
            bool force,
            byte[] data,
            int start,
            int count)
        {
            if (peer == null)
            {
                return;
            }
            lock (_peers)
            {
                if (!_peers.ContainsAddress(peer.EndPoint) || !peer.Shutdown(data, start, count, force))
                {
                    //invalid peer
                    return;
                }
            }
            var netEvent = CreateEvent(NetEventType.Disconnect);

            netEvent.Peer             = peer;
            netEvent.AdditionalData   = socketErrorCode;
            netEvent.DisconnectReason = reason;
            EnqueueEvent(netEvent);
        }
Пример #2
0
 /// <summary>
 /// Disconnect peer from server and send additional data (Size must be less or equal MTU - 8)
 /// </summary>
 /// <param name="peer">peer to disconnect</param>
 /// <param name="data">additional data</param>
 /// <param name="start">data start</param>
 /// <param name="count">data length</param>
 public void DisconnectPeer(NetPeer peer, byte[] data, int start, int count)
 {
     if (peer != null && _peers.ContainsAddress(peer.EndPoint))
     {
         DisconnectPeer(peer, DisconnectReason.DisconnectPeerCalled, 0, true, data, start, count);
     }
 }
Пример #3
0
        /// <summary>
        /// Connect to remote host
        /// </summary>
        /// <param name="target">Server end point (ip and port)</param>
        public void Connect(NetEndPoint target)
        {
            if (!IsRunning)
            {
                throw new Exception("Client is not running");
            }
            lock (_peers)
            {
                if (_peers.ContainsAddress(target) || _peers.Count >= _maxConnections)
                {
                    //Already connected
                    return;
                }

                //Create reliable connection
                //And request connection
                var newPeer = new NetPeer(this, target, 0);
                _peers.Add(target, newPeer);
            }
        }