Reorganized a bit; Added preliminary web socket server.

This commit is contained in:
2023-01-04 01:03:54 -08:00
parent 92986cfb23
commit ac40b29f31
5 changed files with 107 additions and 40 deletions

36
websocket.js Normal file
View File

@@ -0,0 +1,36 @@
import WebSocket, {WebSocketServer} from 'ws'
try {
const server = new WebSocketServer({
port: 3001,
perMessageDeflate: {
zlibDeflateOptions: {
// See zlib defaults.
chunkSize: 1024,
memLevel: 7,
level: 3
},
zlibInflateOptions: {
chunkSize: 10 * 1024
},
// Other options settable:
clientNoContextTakeover: true, // Defaults to negotiated value.
serverNoContextTakeover: true, // Defaults to negotiated value.
serverMaxWindowBits: 10, // Defaults to negotiated value.
// Below options specified as default values.
concurrencyLimit: 10, // Limits zlib concurrency for perf.
threshold: 1024 // Size (in bytes) below which messages
// should not be compressed if context takeover is disabled.
}
})
server.on('connection', function connection(socket) {
socket.on('message', function message(data) {
console.log("received: %s", data)
socket.send("pong")
})
})
}
catch(e) {
console.log(e);
}