Author: markt Date: Fri Nov 9 20:32:01 2012 New Revision: 1407619 URL: http://svn.apache.org/viewvc?rev=1407619&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54127 Add support for sending a WebSocket ping Patch provided by Sean Winterberger
Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java?rev=1407619&r1=1407618&r2=1407619&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original) +++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Fri Nov 9 20:32:01 2012 @@ -301,6 +301,29 @@ public class WsOutbound { * @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 +331,7 @@ public class WsOutbound { doFlush(true); - upgradeOutbound.write(0x8A); + upgradeOutbound.write(0x80 | opcode); if (data == null) { upgradeOutbound.write(0); } else { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org