Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for sending a WebSocket ping
Patch provided by Sean Winterberger

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1407619 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Nov 9, 2012
1 parent 48314f9 commit 8fea85c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion java/org/apache/catalina/websocket/WsOutbound.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,37 @@ public synchronized void close(int status, ByteBuffer data)
* @throws IOException If an error occurs writing to the client
*/
public synchronized void pong(ByteBuffer data) throws IOException {
sendControlMessage(data, Constants.OPCODE_PONG);
}

/**
* Send a ping message to the client
*
* @param data Optional message.
*
* @throws IOException If an error occurs writing to the client
*/
public synchronized void ping(ByteBuffer data) throws IOException {
sendControlMessage(data, Constants.OPCODE_PING);
}

/**
* Generic function to send either a ping or a pong.
*
* @param data Optional message.
* @param opcode The byte to include as the opcode.
*
* @throws IOException If an error occurs writing to the client
*/
private synchronized void sendControlMessage(ByteBuffer data, byte opcode) throws IOException {

if (closed) {
throw new IOException(sm.getString("outbound.closed"));
}

doFlush(true);

upgradeOutbound.write(0x8A);
upgradeOutbound.write(0x80 | opcode);
if (data == null) {
upgradeOutbound.write(0);
} else {
Expand Down

0 comments on commit 8fea85c

Please sign in to comment.