new EasyProtocolFormatter(isLittleEndianopt)
Simple and very fast encoding/decoding.
The simplicity of this formatting provides high performance and easy portability to various platforms.
However this formatting cannot be used when recovery of the broken connection is needed.
Encoding of open connection message:
n.a. - the open connection message is not used. The connection is considered open when the socket is open.
Encoding of close connection message:
n.a. - the close connection message is not used. The connection is considered closed then the socket is closed.
Encoding of data message:
1 byte - type of data: 10 string in UTF8, 40 bytes
4 bytes - length: 32 bit integer indicating the size (in bytes) of message data.
x bytes - message data
Encoding of open connection message:
n.a. - the open connection message is not used. The connection is considered open when the socket is open.
Encoding of close connection message:
n.a. - the close connection message is not used. The connection is considered closed then the socket is closed.
Encoding of data message:
1 byte - type of data: 10 string in UTF8, 40 bytes
4 bytes - length: 32 bit integer indicating the size (in bytes) of message data.
x bytes - message data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isLittleEndian |
Boolean |
<optional> |
true | Indicates if size of data is encoded in little endian or big endian. The default value is true - the little endian is used. |
- Source:
Example
// Create EasyProtocolFormatter.
// Note: Be sure the service side uses EasyProtocolFormatter too.
// Otherwise it will not work because they will not understand each other!
EasyProtocolFormatter aProtocolFormatter = new EasyProtocolFormatter();
// Create the duplex output channel which uses the specified protocol formatter.
var anOutputChannel = new WebSocketDuplexOutputChannel("ws://127.0.0.1:8077/MyService/", null, aProtocolFormatter);
// Subscribe for receving messages.
anOutputChannel.onResponseMessageReceived = onResponseMessageReceived;
// Open connection.
anOutputChannel.openConnection();
...
// Send a message.
// Note: the message can be String or ArrayBuffer.
anOutputChannel.sendMessage("Hello World.");
...
// Close connection when not needed.
anOutputChannel.closeConnection();
...
// Your event handler to process received response messages.
function onResponseMessageReceived(duplexChannelMessageEventArgs) {
var aMessage = duplexChannelMessageEventArgs.Message;
...
}
Methods
-
decodeMessage(arrayBufferMessage) → {ProtocolMessage}
-
Decodes the incoming message.
Parameters:
Name Type Description arrayBufferMessage
ArrayBuffer encoded message data. - Source:
Returns:
- Type
- ProtocolMessage
-
encodeOpenConnectionMessage()
-
Returns null.
- Source:
-
encodeRequestMessage(responseReceiverId, messageData)
-
Encodes the message.
Parameters:
Name Type Description responseReceiverId
id of the client that wants to send the message. This parameter is not used. messageData
String | ArrayBuffer message which shall be sent. - Source: