Trigger websocket bugs
This commit is contained in:
parent
cf5a245b11
commit
f41c4e2a60
@ -17,11 +17,15 @@ let closedClientConnections = 0;
|
|||||||
|
|
||||||
let listenSocket;
|
let listenSocket;
|
||||||
|
|
||||||
|
function getRandomInt(max) {
|
||||||
|
return Math.floor(Math.random() * Math.floor(max));
|
||||||
|
}
|
||||||
|
|
||||||
/* Perform random websockets/ws action */
|
/* Perform random websockets/ws action */
|
||||||
function performRandomClientAction(ws) {
|
function performRandomClientAction(ws) {
|
||||||
console.log("performing random ws action");
|
uWS.print('Random client action');
|
||||||
|
|
||||||
ws.send('test message from client');
|
ws.send('test message from client');
|
||||||
|
uWS.print('Random client action, done');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform random uWebSockets.js action */
|
/* Perform random uWebSockets.js action */
|
||||||
@ -31,7 +35,7 @@ function establishNewConnection() {
|
|||||||
|
|
||||||
ws.on('open', () => {
|
ws.on('open', () => {
|
||||||
/* Open more connections */
|
/* Open more connections */
|
||||||
if (++openedClientConnections < 10) {
|
if (++openedClientConnections < 1) {
|
||||||
establishNewConnection();
|
establishNewConnection();
|
||||||
} else {
|
} else {
|
||||||
/* Stop listening */
|
/* Stop listening */
|
||||||
@ -43,19 +47,30 @@ function establishNewConnection() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
ws.on('message', (data) => {
|
||||||
|
console.log('client got message: ' + data);
|
||||||
performRandomClientAction(ws);
|
performRandomClientAction(ws);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
performRandomClientAction(ws);
|
console.log("client was closed");
|
||||||
|
//performRandomClientAction(ws);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function performRandomServerAction(ws) {
|
function performRandomServerAction(ws) {
|
||||||
console.log("performing random server action");
|
//uWS.print('Random server action');
|
||||||
|
switch (getRandomInt(1)) {
|
||||||
ws.send('a test message');
|
case 0: {
|
||||||
|
ws.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
ws.send('a test message', false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//uWS.print('Done with random server action');
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = uWS./*SSL*/App({
|
const app = uWS./*SSL*/App({
|
||||||
@ -63,20 +78,25 @@ const app = uWS./*SSL*/App({
|
|||||||
cert_file_name: 'misc/cert.pem',
|
cert_file_name: 'misc/cert.pem',
|
||||||
passphrase: '1234'
|
passphrase: '1234'
|
||||||
}).ws('/*', {
|
}).ws('/*', {
|
||||||
/*compression: 0,
|
compression: 0,
|
||||||
maxPayloadLength: 16 * 1024 * 1024,
|
maxPayloadLength: 16 * 1024 * 1024,
|
||||||
idleTimeout: 10,*/
|
idleTimeout: 10,
|
||||||
|
|
||||||
open: (ws, req) => {
|
open: (ws, req) => {
|
||||||
|
uWS.print('Server open event');
|
||||||
performRandomServerAction(ws);
|
performRandomServerAction(ws);
|
||||||
|
uWS.print('Server open event, returning');
|
||||||
},
|
},
|
||||||
message: (ws, message, isBinary) => {
|
message: (ws, message, isBinary) => {
|
||||||
|
console.log('server got message: ' + message.byteLength);
|
||||||
performRandomServerAction(ws);
|
performRandomServerAction(ws);
|
||||||
},
|
},
|
||||||
drain: (ws) => {
|
drain: (ws) => {
|
||||||
|
// todo: dont send over a certain backpressure
|
||||||
//performRandomServerAction(ws);
|
//performRandomServerAction(ws);
|
||||||
},
|
},
|
||||||
close: (ws, code, message) => {
|
close: (ws, code, message) => {
|
||||||
|
console.log('server was closed');
|
||||||
//performRandomServerAction(ws);
|
//performRandomServerAction(ws);
|
||||||
}
|
}
|
||||||
}).any('/*', (res, req) => {
|
}).any('/*', (res, req) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user