Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50a0c8c

Browse files
committed
[1.8.x] support ping/pong listener handling
1 parent7f4a66d commit50a0c8c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

‎src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
importorg.jboss.netty.handler.codec.http.HttpVersion;
9696
importorg.jboss.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
9797
importorg.jboss.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
98+
importorg.jboss.netty.handler.codec.http.websocketx.PingWebSocketFrame;
99+
importorg.jboss.netty.handler.codec.http.websocketx.PongWebSocketFrame;
98100
importorg.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame;
99101
importorg.jboss.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder;
100102
importorg.jboss.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder;
@@ -2274,6 +2276,8 @@ private final class WebSocketProtocol implements Protocol {
22742276
privatestaticfinalbyteOPCODE_CONT =0x0;
22752277
privatestaticfinalbyteOPCODE_TEXT =0x1;
22762278
privatestaticfinalbyteOPCODE_BINARY =0x2;
2279+
privatestaticfinalbyteOPCODE_PING =0x9;
2280+
privatestaticfinalbyteOPCODE_PONG =0xa;
22772281
privatestaticfinalbyteOPCODE_UNKNOWN = -1;
22782282

22792283
// We don't need to synchronize as replacing the "ws-decoder" will process using the same thread.
@@ -2376,6 +2380,10 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
23762380
pendingOpcode =OPCODE_TEXT;
23772381
}elseif (frameinstanceofBinaryWebSocketFrame) {
23782382
pendingOpcode =OPCODE_BINARY;
2383+
}elseif (frameinstanceofPingWebSocketFrame) {
2384+
pendingOpcode =OPCODE_PING;
2385+
}elseif (frameinstanceofPongWebSocketFrame) {
2386+
pendingOpcode =OPCODE_PONG;
23792387
}
23802388

23812389
HttpChunkwebSocketChunk =newHttpChunk() {
@@ -2409,6 +2417,10 @@ public void setContent(ChannelBuffer content) {
24092417
webSocket.onBinaryFragment(rp.getBodyPartBytes(),frame.isFinalFragment());
24102418
}elseif (pendingOpcode ==OPCODE_TEXT) {
24112419
webSocket.onTextFragment(frame.getBinaryData().toString(UTF8),frame.isFinalFragment());
2420+
}elseif (pendingOpcode ==OPCODE_PING) {
2421+
webSocket.onPing(rp.getBodyPartBytes());
2422+
}elseif (pendingOpcode ==OPCODE_PONG) {
2423+
webSocket.onPong(rp.getBodyPartBytes());
24122424
}
24132425

24142426
if (frameinstanceofCloseWebSocketFrame) {

‎src/main/java/com/ning/http/client/providers/netty/NettyWebSocket.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
importcom.ning.http.client.websocket.WebSocketByteListener;
1717
importcom.ning.http.client.websocket.WebSocketCloseCodeReasonListener;
1818
importcom.ning.http.client.websocket.WebSocketListener;
19+
importcom.ning.http.client.websocket.WebSocketPingListener;
20+
importcom.ning.http.client.websocket.WebSocketPongListener;
1921
importcom.ning.http.client.websocket.WebSocketTextListener;
2022
importorg.jboss.netty.channel.Channel;
2123
importorg.jboss.netty.channel.ChannelFutureListener;
@@ -213,6 +215,20 @@ protected void onTextFragment(String message, boolean last) {
213215
}
214216
}
215217

218+
publicvoidonPing(byte[]payload) {
219+
for (WebSocketListenerlistener :listeners) {
220+
if (listenerinstanceofWebSocketPingListener)
221+
WebSocketPingListener.class.cast(listener).onPing(payload);
222+
}
223+
}
224+
225+
publicvoidonPong(byte[]payload) {
226+
for (WebSocketListenerlistener :listeners) {
227+
if (listenerinstanceofWebSocketPongListener)
228+
WebSocketPongListener.class.cast(listener).onPong(payload);
229+
}
230+
}
231+
216232
protectedvoidonError(Throwablet) {
217233
for (WebSocketListenerl :listeners) {
218234
try {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp