webhub.js
function ws_send(socket, data) {
	//console.log("send: " + data);
	let header;
	let payload = new Buffer.from(data);
	const len = payload.length;
	
	if (len <= 125) {
		header = new Buffer.alloc(2);
		header[1] = len;
	} else if (len <= 0xffff) {
		header = new Buffer.alloc(4);
		header[1] = 126;
		header[2] = (len >> 8) & 0xff;
		header[3] = len & 0xff;
	} else { /* 0xffff < len <= 2^63 */
		header = new Buffer(10);
		header[1] = 127;
		header[2] = (len >> 56) & 0xff;
		header[3] = (len >> 48) & 0xff;
		header[4] = (len >> 40) & 0xff;
		header[5] = (len >> 32) & 0xff;
		header[6] = (len >> 24) & 0xff;
		header[7] = (len >> 16) & 0xff;
		header[8] = (len >> 8) & 0xff;
		header[9] = len & 0xff;
	}
	
	header[0] = 0x81;
	socket.write(Buffer.concat([header, payload],
		 header.length + payload.length), 'binary');
	//console.log('sent ' + data.length + ' bytes');
}
function ws_send(socket, data) {
	//console.log("send: " + data);
	let header;
	let payload = new Buffer.from(data);
	const len = payload.length;
	
	if (len <= 125) {
		header = new Buffer.alloc(2);
		header[1] = len;
	} else if (len <= 0xffff) {
		header = new Buffer.alloc(4);
		header[1] = 126;
		header[2] = (len >> 8) & 0xff;
		header[3] = len & 0xff;
	} else { /* 0xffff < len <= 2^63 */
		header = new Buffer(10);
		header[1] = 127;
		header[2] = (len >> 56) & 0xff;
		header[3] = (len >> 48) & 0xff;
		header[4] = (len >> 40) & 0xff;
		header[5] = (len >> 32) & 0xff;
		header[6] = (len >> 24) & 0xff;
		header[7] = (len >> 16) & 0xff;
		header[8] = (len >> 8) & 0xff;
		header[9] = len & 0xff;
	}
	
	header[0] = 0x81;
	socket.write(Buffer.concat([header, payload],
		 header.length + payload.length), 'binary');
	//console.log('sent ' + data.length + ' bytes');
}
function ws_send ( socket , data ) { //console.log("send: " + data); let header ; let payload = new Buffer . from ( data ) ; const len = payload . length ; if ( len <= 125 ) { header = new Buffer . alloc ( 2 ) ; header [ 1 ] = len ; } else if ( len <= 0xffff ) { header = new Buffer . alloc ( 4 ) ; header [ 1 ] = 126 ; header [ 2 ] = ( len >> 8 ) & 0xff ; header [ 3 ] = len & 0xff ; } else { /* 0xffff < len <= 2^63 */ header = new Buffer ( 10 ) ; header [ 1 ] = 127 ; header [ 2 ] = ( len >> 56 ) & 0xff ; header [ 3 ] = ( len >> 48 ) & 0xff ; header [ 4 ] = ( len >> 40 ) & 0xff ; header [ 5 ] = ( len >> 32 ) & 0xff ; header [ 6 ] = ( len >> 24 ) & 0xff ; header [ 7 ] = ( len >> 16 ) & 0xff ; header [ 8 ] = ( len >> 8 ) & 0xff ; header [ 9 ] = len & 0xff ; } header [ 0 ] = 0x81 ; socket . write ( Buffer . concat ( [ header , payload ] , header . length + payload . length ) , 'binary' ) ; //console.log('sent ' + data.length + ' bytes'); }
send string data to web socket
send string data to web socket