Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
7 changes: 4 additions & 3 deletions nativeWs/justWs.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
console.log(ws);

ws.onopen = (event)=>{
ws.send('I am so excited I am connected! It is like Christmas!');
console.log(event);
ws.send("I'm so excited I'm connected to the server. It's like my country just won the World Cup!")
}

ws.onmessage = (event)=>{
console.log(event);
ws.onmessage = (message)=>{
console.log(message.data);
}

</script>
24 changes: 13 additions & 11 deletions nativeWs/justWsServer.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// http is a core node module
const http = require('http');
// 3rd party module, ws!
//ws is a 3rd party module
const websocket = require('ws');

const server = http.createServer((req, res)=>{
res.end("I am connected!")
res.end('I am connected!');
});

const wss = new websocket.Server({server})
wss.on('headers',(headers,req)=>{
console.log(headers)
});
const wss = new websocket.WebSocketServer({server});

// wss.on('headers',(headers, req)=>{
// console.log(headers);
// })

wss.on('connection', (ws,req)=>{
ws.send('Welcome to the websocket server!!')
ws.on('message',(msg)=>{
console.log(msg)
wss.on('connection',(ws,req)=>{
// console.log(ws);
ws.send('Welcome to the websocket server!!!');
ws.on('message',(data)=>{
console.log(data.toString());
})
})


server.listen(8000);
45 changes: 34 additions & 11 deletions nativeWs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nativeWs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ws": "^6.1.0"
"ws": "^8.11.0"
}
}
Loading