public bool Close() { clientSocket?.Close(); clientSocket = null; serverNetworkStream?.Close(); serverNetworkStream = null; return(true); }
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; }
protected virtual void Dispose(bool disposing) { if (disposing) { if (networkStream != null) { networkStream.Close(); networkStream = null; } } }
/// <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)); } }
/// <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)); }
/// <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 { } }
protected void OnTerminate() { _tcpClient.Close(); _stream.Close(); }