WebSockets with NodeJS (Express) and WebSocket API
HTML-код
- Опубликовано: 13 май 2020
- How to set up a WebSockets Client and Server and Connect them!
-------------------------------------
Code: github.com/Vuka951/tutorial-c...
WebSocket API:
* developer.mozilla.org/en-US/d...
* developer.mozilla.org/en-US/d...
WS (WebSocket): www.npmjs.com/package/ws
--------------------------------------
Thanks for watching, if the video was helpful to you a like and/or a star to the github repo would be appreciated ❤️
Spent the whole day today to follow a 2 hours turorial on a web-socket-application and it didn't work, and I could't find the bug. And it felt like I didn't even understand what exactly I was coding on each line. This helped me capture it better. Thank you.
This is SO GREAT man. Exactly the amount of data necessary and the amount of pointing where to find out more. Great flow, very dense in information.
Thank you.
I was struggling to get some concise guideline on this as an entry level coder and you made my day.
After 4 days of torture I finally find your video. Simple and easy. You are the best, man.
Glad it was helpful!
bro, finally someone who explained this websocket communication right for beginnerrs. Thx a lot! u saved my project
I've have been looking for an explanation on how to use websockets for 5 hours. I've been losing my mind about the amount of unclear explanations there were. You just saved my day and also my sanity. Thank you
Thanks man, this simple explanation really helped with cramping websockets into my vue project.
Huge thanks ! this was exactly what I needed !
the very bare bones approach to WS.
thanks bro I overcomplicated things but this really helped me understand
You are awesome, amazing and marvelous. This is a fantastic tutorial.
wow... that was smooth... it will help me tomorrow but thank you today.
Have been so much help, thanks a lot!
Thank you, great work. It's very helpful
How isn't possible leave more than one like on this awsome video ?
Before recording, I suggest increasing your vscode font to 17-20, it will really help us, thank you
Great tutorial. One question though, how can you send to specific client?
very clear explanation.
Thanks, great video!🔥 I use this in future video tutorial in my yt channel
very nice video short sweet and explained very well thanks :)
Websocket Update: Add another parameter, in ws.on('message'... called isBinary for sending to other clients excluding itself because they will be encrypted if I'm not mistaken. Kinda like this
ws.on('message', function message(data, isBinary) {
wss.clients.forEach(function each(client) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(data, { binary: isBinary });
}
});
Very useful, thank you!
Glad to hear that!
Helped a Lot !!!!!
For example if i want to send some data from server to client, but in a custom event. on the server side, in connection event i need to send the event, like
wss.on('connection', function connection(ws){
ws.send('myCustomEvent', someData);
});
and in the client side i just need to add an event listener to receive that custom event?
socket.addEventListener('myCustomEvent', (data) => {
console.log(data.data)
})
bingo you’re awesome dude!
I like the console group chart!
amazing man thanks alot :)
Glad it helped!
Thanks a lot sir!
How do you use the same express port in ws?
how to authentication and authorization using jwt in websocket ws
Nice video thanks
great video
Can We Uniquely Identify this client ? And Do some Action based on which client closed the Connection ??
wooooooza i like hardcore codding thou I am not that good so keep the good vibe going
how can use this method to firebase web hosting
why do you have to open the file directly? I want to navigate to port 3000 not open file with browser. I copied example from npm ws word for word and then copied the websocket browser example from mozilla developer word for word and it doesnt work. My browser goes into infinite load.
did you find the solution for opening the page in localhost:3000 (any port number)
good video
i tried the same code but in client side instead of showing hello from client1 its showing blob{size:19 type:" "} if u know how to solve the issue kindly let me know
thank you
Sir my websocket url require authentication how to connect. Please share some code or video
good video. it could have been better if you used a bigger font, but great video anyways.
how do you save all connections
I know when the user make a connection we can have an array such as const user = []
then we push each socket and user id from our front end, in case someone logs in to our server with jwt and gets the his user profile such as { id: xxxx, name: asss, email:add@hotmail.com}
so we can push the user id or his email (unique) to that array along side the socket correct.
can we store them in redis and if a connections is lost we can update that socket in redis ? or how do you go about implementing this
thanks
How can use it in real server hosting ??
i like for the topics and explanation, i dislike for readibility, the text to small, you need to zoom it later
Next time please increase font size
I need help
hello friend..i get the error when running a node index.js file
const wss = new WebSocket.Server({ server:server });
^
TypeError: WebSocket.Server is not a constructor
What is the difference between ws and websocket ?? I'm really confused
Two different libraries but both with the dame basic function
@@nclsDesign I figured, in a month
@@nclsDesign I think its not dame.
@@thenextbigthing1393 Not the same but the SAME BASIC FUNCTION, as I said.
Bruh, next time add some zoom, I can't see that well