public interface FrameChannel
FrameChannel
represents a full duplex communication
channel as defined by RFC 6455. Any instance of this will provide
a means to perform asynchronous writes and reads to a remote client
using a lightweight framing protocol. A frame is a finite length
sequence of bytes that can hold either text or binary data. Also,
control frames are used to perform heartbeat monitoring and closure.
For convenience frames can be consumed from the socket via a callback to a registered listener. This avoids having to poll each socket for data and provides a asynchronous event driven model of communication, which greatly reduces overhead and complication.
FrameListener
,
Frame
Modifier and Type | Method and Description |
---|---|
void |
close()
This is used to close the connection without a specific reason.
|
void |
close(Reason reason)
This is used to close the connection with a specific reason.
|
void |
register(FrameListener listener)
This is used to register a
FrameListener to this
instance. |
void |
remove(FrameListener listener)
This is used to remove a
FrameListener from this
instance. |
void |
send(byte[] data)
This is used to send data to the connected client.
|
void |
send(Frame frame)
This is used to send data to the connected client.
|
void |
send(String text)
This is used to send text to the connected client.
|
void send(byte[] data) throws IOException
data
- this is the data that is to be sentIOException
void send(String text) throws IOException
text
- this is the text that is to be sentIOException
void send(Frame frame) throws IOException
frame
- this is the frame that is to be sentIOException
void register(FrameListener listener) throws IOException
FrameListener
to this
instance. The registered listener will receive all user frames
and control frames sent from the client. Also, when the frame
is closed or when an unexpected error occurs the listener is
notified. Any number of listeners can be registered at any time.listener
- this is the listener that is to be registeredIOException
void remove(FrameListener listener) throws IOException
FrameListener
from this
instance. After removal the listener will no longer receive
any user frames or control messages from this specific instance.listener
- this is the listener to be removedIOException
void close(Reason reason) throws IOException
reason
- the reason for closing the connectionIOException
void close() throws IOException
IOException
Copyright © 2023. All rights reserved.