Index: java/org/apache/catalina/websocket/WsOutbound.java =================================================================== --- java/org/apache/catalina/websocket/WsOutbound.java (revision 1407594) +++ java/org/apache/catalina/websocket/WsOutbound.java (working copy) @@ -25,6 +25,7 @@ import org.apache.coyote.http11.upgrade.UpgradeOutbound; import org.apache.tomcat.util.buf.B2CConverter; import org.apache.tomcat.util.res.StringManager; +import org.apache.catalina.websocket.Constants; /** * Provides the means to write WebSocket messages to the client. All methods @@ -301,6 +302,29 @@ * @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")); @@ -308,7 +332,7 @@ doFlush(true); - upgradeOutbound.write(0x8A); + upgradeOutbound.write(0x80 | opcode); if (data == null) { upgradeOutbound.write(0); } else {