コード例 #1
0
        /// <summary>
        ///     Sends the specified packet to the client
        /// </summary>
        /// <param name="packet">The packet to send</param>
        /// <exception cref="Exception">Not connected</exception>
        private void SendPacket(RemoteConPacket packet)
        {
            if (!_client.Connected)
            {
                throw new Exception("Not connected.");
            }

            var packetBytes = packet.GetBytes();

            //_ns.Write(packetBytes, 0, packetBytes.Length);
            _ns.BeginWrite(packetBytes, 0, packetBytes.Length - 1, ar => { _ns.EndWrite(ar); }, null);
        }
コード例 #2
0
        /// <summary>
        ///     Sends the specified packet to the client
        /// </summary>
        /// <param name="packet">The packet to send</param>
        /// <exception cref="Exception">Not connected</exception>
        private void SendPacket(RemoteConPacket packet)
        {
            if (_client == null || !_client.Connected)
            {
                throw new Exception("Not connected.");
            }

            var packetBytes = packet.GetBytes();

            try
            {
                _ns.BeginWrite(packetBytes, 0, packetBytes.Length - 1, ar => { _ns.EndWrite(ar); }, null);
            }
            catch (ObjectDisposedException) { } // Do not write to NetworkStream when it's closed.
            catch (IOException) { }             // Do not write to Socket when it's closed.
        }
コード例 #3
0
        /// <summary>
        ///     Sends the specified packet to the client
        /// </summary>
        /// <param name="packet">The packet to send</param>
        /// <exception cref="Exception">Not connected</exception>
        private void SendPacket(RemoteConPacket packet)
        {
            if (_isUnitTest)
            {
                return;
            }

            if (!_connected)
            {
                throw new Exception("Not connected.");
            }

            var ackBytes = packet.GetBytes();

            _ns.Write(ackBytes, 0, ackBytes.Length - 1);
        }