Class LocalTcpClient
- Namespace
- VpnHood.Net.TcpStack
- Assembly
- VpnHood.Net.TcpStack.dll
Represents a connection a LocalTcpListener accepted: its endpoints and the stream it owns.
public sealed class LocalTcpClient : ITcpClient, IAsyncDisposable, IDisposable
- Inheritance
-
LocalTcpClient
- Implements
- Inherited Members
Properties
LocalEndPoint
Gets the connection's local endpoint: the address and port the peer connected to.
public IPEndPoint LocalEndPoint { get; }
Property Value
RemoteEndPoint
Gets the connection's remote endpoint: the peer's address and port.
public IPEndPoint RemoteEndPoint { get; }
Property Value
Stream
Gets the stream that reads and writes the connection's data.
public Stream Stream { get; }
Property Value
Remarks
A read returns what is buffered, which may be less than asked. After the peer's FIN, reads return the rest and then 0, and the stream can still write: a half-close. After a reset or an abort, reads also return what is buffered, then 0.
A write completes once all its data has gone through the send path: each segment is buffered and handed to OnPacketSend, waiting for room in the peer's window and in the buffer, which acknowledgments free. Its completion does not mean the peer acknowledged the data. It throws IOException once the connection is closed for writing, and ObjectDisposedException after disposal; a write that is canceled or fails may have sent part of the data. FlushAsync(CancellationToken) does nothing: data goes out as the window allows. CanWrite turns false once the connection is closed for writing.
One read and one write may run at the same time.
Methods
Dispose()
Disposes the stream and starts closing the connection: the peer gets a FIN, whose exchange the stack completes after this method returns. If received data is still unread, the peer gets a reset instead: at once when it has acknowledged everything sent, or else after the FIN, once it acknowledges the rest.
public void Dispose()
DisposeAsync()
Disposes the stream and starts closing the connection, as Dispose() does; it does not wait for the close to complete.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.