YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.sendspin.session.WsConnection Class Reference

The messages of one WebSocket connection (RFC 6455) after the opening handshake: complete text and binary messages in, frames out. More...

Inheritance diagram for de.yaacc.sendspin.session.WsConnection:
Inheritance graph
Collaboration diagram for de.yaacc.sendspin.session.WsConnection:
Collaboration graph

Classes

class  ClosedException
 The peer closed the connection with a close frame (which has been answered).
 
class  Message
 A complete message.
 
class  ViolationException
 The peer broke the rules of the protocol; a close frame with code() was sent.
 

Public Member Functions

 WsConnection (InputStream in, OutputStream out, boolean client, int maxMessageBytes, SecureRandom random)
 
long lastPongNanos ()
 The time of the last pong, from System#nanoTime(); 0 if none came.
 
Message receive () throws IOException
 Blocks for the next complete message.
 
void sendText (String text) throws IOException
 
void sendBinary (byte[] data) throws IOException
 
void sendPing (byte[] payload) throws IOException
 
void close (int code, String reason) throws IOException
 Sends a close frame (once) and flushes; the caller closes the streams.
 
void close () throws IOException
 

Static Public Attributes

static final int CLOSE_NORMAL = 1000
 
static final int CLOSE_PROTOCOL_ERROR = 1002
 
static final int CLOSE_INVALID_DATA = 1007
 
static final int CLOSE_TOO_BIG = 1009
 

Detailed Description

The messages of one WebSocket connection (RFC 6455) after the opening handshake: complete text and binary messages in, frames out.

A subset that is enough for Sendspin and strict about what it reads: no extensions, a size cap for every message and frame, reserved bits and unknown opcodes are errors, a client does not accept masked frames and a server only masked ones, control frames are at most 125 bytes and never fragmented, a text message must be UTF-8, fragments of two messages never interleave. Pings are answered here; a close is answered and ends the connection with a ClosedException; a violation sends a close frame with the matching code and ends it with a ViolationException.

One thread reads (receive()); any thread may send. A SocketTimeoutException from receive() means that nothing arrived and the connection is intact; a timeout inside a frame is a plain IOException (the connection is lost).

Constructor & Destructor Documentation

◆ WsConnection()

de.yaacc.sendspin.session.WsConnection.WsConnection ( InputStream in,
OutputStream out,
boolean client,
int maxMessageBytes,
SecureRandom random )
Parameters
clienttrue for the side that opened the connection (it masks what it sends)
maxMessageBytesthe largest message (and frame) this side accepts

The documentation for this class was generated from the following file: