Post

PipesConnection

Manages a connection between a server and a client.


Remarks

Manages a connection between a server and a client. PipesServer creates one for each client and passes it to its ClientConnected, ClientDisconnected and ClientMessage events.


Constructors

SyntaxDescription
PipesConnection(int id, string name, PipeStream serverStream)Constructor that passes the stream from the server, plus any identifiers.

Properties

IdentifierTypeDescription
IDintNumeric identifier. A read-only field.
IsConnectedboolIndicates if stream is connected.
NamestringString identifier for the client in this connected stream.
TheStreamPipeStreamThe stream between server and client.

Events

IdentifierTypeDescription
DisconnectedPipeConnectionEventIndicates the stream has been disconnected.
ErrorPipeConnectionExceptionEventIndicates an error.
ReceiveMessagePipeConnectionMessageEventIndicates that the stream received a message.

Methods

MethodReturnsDescription
Close()voidCloses the stream.
Open()voidOpens the connection for reading and writing.
Send(PipeMessage message)voidPuts a PipeMessage in the queue to be sent.

Delegates

DelegateReturnsDescription
PipeConnectionEvent(PipesConnection pc)voidHandles a connection state event, such as disconnection.
PipeConnectionMessageEvent(PipesConnection pc, PipeMessage message)voidHandles a message received on a connection.
PipeConnectionExceptionEvent(PipesConnection pc, Exception ex)voidHandles an error on a connection.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using Nova.IPC.Pipes;

PipesServer server = new PipesServer("NovaDemoServer");

// The server passes each client's PipesConnection to its events.
server.ClientConnected += connection =>
{
  Console.WriteLine(connection.Name + " connected: " + connection.IsConnected);

  PipeMessage welcome = new PipeMessage();
  welcome.EncodeString("Welcome.");
  connection.Send(welcome);
};

server.Start();
This post is licensed under CC BY 4.0 by the author.

Trending Tags