TsgcWSConnection

TsgcWSConnection is a wrapper for client WebSocket connections. You can access this object in Server or Client Events.

 

Methods

  WriteData: sends a message to the client.

 

  WriteSSEEvent: writes one server-sent event to a connection whose Transport is trpSSE: an "event:" line with the event name (omitted when empty), an "id:" line with the id (omitted when empty), one "data:" line per line of the data, and the blank line that ends the event. CR and LF are removed from the event name and the id. The whole event is written under the critical section of the connection, so it never interleaves with another write, and it is queued as one item when a text queue is configured. It does nothing on any other transport.

 

  WriteSSEComment: writes a comment line (": text") and the blank line to a trpSSE connection. Browsers ignore a comment, so it is the way to keep an idle stream alive through a proxy. Comments are never queued.

 

  Close: sends a close message to other peer. A "CloseCode" can be specified optionally. By default, the value sent is NORMAL close code. If you send a negative close code, the reason for closing will not be sent.

 

  Disconnect: close client connection from the server side. A "CloseCode" can be specified optionally.

 

  Ping: sends a ping to the client.

 

  AddTCPEndOfFrame: if connection is plain TCP, allows you to set which byte/s define the end of message. Message is buffered till is received completely.

 

  Subscribed: returns if the connection is subscribed to a custom channel.

 

  Subscribe: subscribe this connection to a channel. Later you can Broadcast a message from server component to all connections subscribed to this channel.

 

  UnSubscribe: unsubscribe this connection from a channel.

 

 

Properties

  Protocol: returns sub-protocol used on this connection.

 

  IP: returns Peer IP Address.

 

  Port: returns Peer Port.

 

  LocalIP: returns Host IP Address.

 

  LocalPort: returns Host Port.

 

  URL: returns URL requested by the client.

 

  Guid: returns connection ID.

 

  HeadersRequest: returns a list of Headers received on Request.

 

  HeadersResponse: returns a list of Headers sent as Response.

 

  RecBytes: number of bytes received.

 

  SendBytes: number of bytes sent.

 

  PendingCount: number of messages still queued for this connection, added across the three priority levels of QueueOptions. Returns 0 when nothing is queued, and reading it allocates nothing. Use it to run a credit window on top of the OnQueueDrained event, or to detect a consumer that is falling behind. This property is read-only, and it is available on the managed .NET connection with the same meaning.

 

  Transport: returns the transport type of connection:

 

trpRFC6455: a normal WebSocket connection.

 

trpHixie76: a WebSocket connection using draft WebSocket spec.

 

trpSSE: a Server-Sent Events connection.

 

trpTCP: plain TCP connection.

 

 

TCPEndOfFrameScanBuffer: allows defining which method use to find end of message (if using trpTCP as transport).

 

eofScanNone: every time a new packet arrives, the OnBinary event is called.

 

eofScanLatestBytes: if latest bytes are equal to bytes added with AddTCPEndOfFrame method, OnBinary message is called, otherwise this packet is buffered

 

eofScanAllBytes: searches in the entire packet for bytes equal to bytes added with the AddTCPEndOfFrame method. If found, the OnBinary event is called, otherwise this packet is buffered

 

  Data: user session data object, here you can pass an object and access this every time you need, for example: you can pass a connection to a database, user session properties...