Kevin Powell - CommunityKP-C
Kevin Powell - Communityβ€’4w agoβ€’
18 replies
Faker

Web Socket server Vs HTTP Server

Hello, I was reading a bit on web sockets and wanted to implement them in my project. Just wanted to discuss about what I've learnt.

So at first, I thought web sockets runs on a web server but it seems I was wrong? I needed to start a "web socket" server, only then I was able to communicate to that particular server.

Can someone explain why please, at first I thought I would have a normal web server like using express or Hono, run that server, then have a route that would handle my web socket.

From what I've learn for this to work this way (I think), is to upgrade a particular request to web socket using upgrade headers and all? Can anyone elaborate on that pls. I'm kinda lost too many information at once :c.

Is the idea like: Create a web server using express/Hono, then run a function that creates a web socker server and activates it? But doing that, small question though, is the web socket server going to "block" any other code from running or it runs just like JS, meaning it run based on events?

side thing:

I came across this article: Node behaving as web socket client. I was confused by that, previously, if I wanted a script to run containing web sockets, using node, I would need to use third party libraries like ws or socket.io but now node has a default web socket api similar to what the browser uses? So I can replicate what can be done using client web socket from browser using node?
Was this page helpful?