Skip to content

Instantly share code, notes, and snippets.

@majek
Created February 9, 2012 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majek/1781022 to your computer and use it in GitHub Desktop.
Save majek/1781022 to your computer and use it in GitHub Desktop.
Misultin close websockets bug
var net = require('net');
console.log(" [.] Connecting to localhost:8000");
var conn = net.createConnection(8000, '127.0.0.1');
var data = [
"GET /echo/1/1/websocket HTTP/1.1",
"Upgrade: websocket",
"Connection: Upgrade",
"Host: localhost",
"Origin: http://localhost:8000",
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version: 13",
"", ""]
conn.on('connect', function() {
conn.write(data.join('\r\n'), 'binary');
setTimeout(function(){
conn.write(new Buffer([0x88, 0x00]), 'binary');
// conn.write(new Buffer([0x88, 0x80, 0xaa, 0xaa, 0xaa, 0xaa]), 'binary');
}, 200);
});
conn.once('data', function(d) {
console.log(JSON.stringify(d.toString()));
});
#!/usr/bin/env escript
%%! -smp disable +A1 +K true -pz ./ebin -pa deps/misultin/ebin -input
-module(misultin_ws_close_bug).
-mode(compile).
-export([main/1]).
main(_) ->
Port = 8000,
io:format(" [*] Running at http://localhost:~p~n", [Port]),
misultin:start_link(
[{port, Port},
{autoexit, false},
{ws_autoexit, false},
{loop, fun (Req) -> handle_http(Req) end},
{ws_loop, fun (Req) -> handle_ws(Req) end}]),
receive
_ -> ok
end.
handle_http(Req) ->
Req:respond(404,
<<"404 - Nothing here\n">>).
handle_ws(Req) ->
Req:send(<<"deadbabe">>),
handle_ws0(Req).
handle_ws0(Req) ->
receive
closed -> io:format("Got closed event!~n");
Any ->
io:format("Got: ~p~n", [Any]),
handle_ws0(Req)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment