Last active
April 27, 2017 12:44
-
-
Save zhoulifu/ac3cff3f49989d6853b6a73b0b53afd0 to your computer and use it in GitHub Desktop.
Demo to produce 'bad rsv 4''
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.InetSocketAddress; | |
import java.net.URI; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.TimeUnit; | |
import org.java_websocket.WebSocket; | |
import org.java_websocket.WebSocketImpl; | |
import org.java_websocket.client.WebSocketClient; | |
import org.java_websocket.drafts.Draft; | |
import org.java_websocket.drafts.Draft_17; | |
import org.java_websocket.handshake.ClientHandshake; | |
import org.java_websocket.handshake.ServerHandshake; | |
import org.java_websocket.server.WebSocketServer; | |
class Client extends WebSocketClient { | |
Client(URI serverUri) { | |
super(serverUri); | |
} | |
@Override | |
public void onOpen(ServerHandshake serverHandshake) { | |
//NO-OP | |
} | |
@Override | |
public void onMessage(String s) { | |
//NO-OP | |
} | |
@Override | |
public void onClose(int i, String s, boolean b) { | |
//NO-OP | |
} | |
@Override | |
public void onError(Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
class Server extends WebSocketServer { | |
Server(InetSocketAddress address, List<Draft> drafts) { | |
super(address, drafts); | |
} | |
@Override | |
public void onOpen( | |
final WebSocket webSocket, ClientHandshake clientHandshake) { | |
//NO-OP | |
} | |
@Override | |
public void onClose(WebSocket webSocket, int i, String s, boolean b) { | |
//NO-OP | |
} | |
@Override | |
public void onMessage(WebSocket webSocket, String s) { | |
//NO-OP | |
} | |
@Override | |
public void onError(WebSocket webSocket, Exception e) { | |
//NO-OP | |
} | |
@Override | |
public void onStart() { | |
BadRSV.startLatch.countDown(); | |
} | |
} | |
public class BadRSV { | |
private static final Draft DRAFT = new Draft_17(); | |
public static final CountDownLatch startLatch = new CountDownLatch(1); | |
static { | |
WebSocketImpl.DEBUG = true; | |
} | |
public static void main(String[] args) throws InterruptedException { | |
Server server = new Server(new InetSocketAddress("localhost", 8080), | |
Collections.singletonList(DRAFT)); | |
server.start(); | |
startLatch.await(); | |
Client client = new Client(URI.create("ws://localhost:8080")); | |
client.connect(); | |
TimeUnit.MILLISECONDS.sleep(50); | |
client.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write(153): {GET / HTTP/1.1 | |
Connection: Upgrade | |
Host: localhost:8080 | |
Sec-WebSocket-Key: o/Et8V6ZSwi6K/0hydg/2g== | |
Sec-WebSocket-Version: 13 | |
Upgrade: websocket | |
} | |
process(153): {GET / HTTP/1.1 | |
Connection: Upgrade | |
Host: localhost:8080 | |
Sec-WebSocket-Key: o/Et8V6ZSwi6K/0hydg/2g== | |
Sec-WebSocket-Version: 13 | |
Upgrade: websocket | |
} | |
org.java_websocket.exceptions.InvalidFrameException: bad rsv 4 | |
at org.java_websocket.drafts.Draft_10.translateSingleFrame(Draft_10.java:297) | |
at org.java_websocket.drafts.Draft_10.translateFrame(Draft_10.java:273) | |
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:318) | |
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:154) | |
at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:241) | |
at java.lang.Thread.run(Thread.java:745) | |
write(129): {HTTP/1.1 101 Switching Protocols | |
Connection: Upgrade | |
Sec-WebSocket-Accept: m+lzNTcC9gXRbi/++l30hc8ZsS4= | |
Upgrade: websocket | |
} | |
open using draft: Draft_17 | |
process(129): {HTTP/1.1 101 Switching Protocols | |
Connection: Upgrade | |
Sec-WebSocket-Accept: m+lzNTcC9gXRbi/++l30hc8ZsS4= | |
Upgrade: websocket | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment