So I'm close, I can send 1 line, but I'm confused on why exactly this is failing (little new to this).
\x81 I'm assuming this is whatever an opcode is. 0, 1, and 2 are valid, 3+ fails with an "invalid opcode"
\x05 I assumed this is the legnth of what I'm trying to send, "test\r\n" being 5 bytes, right? Why would
\x04 with "test" make it return as a blob in Chrome?
http://stackoverflow.com/a/8125509 ?
if(!isObject(WebSocket)) {
new TCPObject(WebSocket) {
port = 27998;
debug = 3;
};
WebSocket.setBinary(0);
WebSocket.listen(WebSocket.port);
}
if(!isObject(WebSocketClients)) {
new SimGroup(WebSocketClients);
}
exec("./base64.cs");
function WebSocket::onConnectRequest(%this, %ip, %socket) {
echo("Requested connection from" SPC %ip SPC %socket);
%client = new TCPObject(WebSocketClient, %socket) {
ip = %ip;
socket = %socket;
};
WebSocketClients.add(%client);
}
function WebSocket::onLine(%this, %line) {
echo("[Server] Data received from" SPC %this.ip @ ":" SPC %line);
}
function WebSocketClient::onLine(%this, %line) {
if(strlwr(getWord(%line, 0)) $= "sec-websocket-key:") {
%ws_key = trim(getWord(%line, 1));
echo("WS handshake key is" SPC %ws_key);
%accept_key = convertWebKey(%ws_key @ "258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
echo("Accept key:" SPC %accept_key);
%this.send("HTTP/1.1 101 Switching Protocols\r\n");
%this.send("Upgrade: websocket\r\n");
%this.send("Connection: Upgrade\r\n");
%this.send("Sec-WebSocket-Accept: " @ %accept_key @ "\r\n");
%this.send("\r\n");
}
echo(%line);
}
base64.cs, might be irrelevantI figured this would be neat for real-time stats of servers, something like a leaderboard, chat, etc.