Ejemplo n.º 1
0
        public bool Close()
        {
            clientSocket?.Close();
            clientSocket = null;

            serverNetworkStream?.Close();
            serverNetworkStream = null;

            return(true);
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (_stream != null)
     {
         _logger.LogMessage("Socket", LogLevel.Verbose, "Closing existing network stream.");
         _stream.Close();    // also closes the socket
         _stream = null;
     }
     _socket = null;
 }
Ejemplo n.º 3
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (networkStream != null)
         {
             networkStream.Close();
             networkStream = null;
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requests">Requests to send</param>
        /// <returns>Responses from the server</returns>
        public Message[] SendRequests(Message[] requests)
        {
            byte[] requestsBytes;
            int    count = _converter.MessagesToBytes(out requestsBytes, requests);

            ITcpClient _tcpClient = _tcpFactory.Create();

            _tcpClient.Connect(_address, _port);
            using (INetworkStream networkStream = _tcpClient.GetStream())
            {
                networkStream.Write(requestsBytes, count);
                byte[] responseBytes = new byte[Properties.Settings.Default.MaxBufferSize];
                int    len           = networkStream.Read(responseBytes, Properties.Settings.Default.MaxBufferSize);
                networkStream.Close();
                _tcpClient.Close();
                return(_converter.BytesToMessages(responseBytes, len));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Close the connection to the Folding@Home client server.
 /// </summary>
 public void Close()
 {
     // stop the timer
     _timer.Stop();
     // close the network stream
     if (_stream != null)
     {
         _stream.Close();
     }
     // remove reference to the network stream
     _stream = null;
     // close the actual connection
     _tcpClient.Close();
     // send connected event
     OnConnectedChanged(new ConnectedChangedEventArgs(false)); // maybe use Connected property?
     // send status message
     OnStatusMessage(new StatusMessageEventArgs("Connection closed.", TraceLevel.Info));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Notifies sessions of closing and then closes the network stream and client (does not raise events)
        /// </summary>
        private void _closeInternal()
        {
            // close and clear any pending sessions
            foreach (var s in _pendingSessions)
            {
                s.Value.NotifyConnectionClose();
            }
            _pendingSessions.Clear();

            // close and clear any active sessions
            foreach (var s in _activeSessions)
            {
                s.Value.NotifyConnectionClose();
            }
            _activeSessions.Clear();

            // TODO: use in network stream read
            _cts.Cancel();

            try
            {
                _streamDecoderTask.Dispose();
            }
            catch { }

            // close transport resources
            try
            {
                _networkStream.Close();
            }
            catch { }

            try
            {
                _tcpClient.Close();
            }
            catch { }
        }
Ejemplo n.º 7
0
 protected void OnTerminate()
 {
     _tcpClient.Close();
     _stream.Close();
 }