Way to integrate socket.io in NextJs app
Answered
Allen's Hummingbird posted this in #help-forum
Allen's HummingbirdOP
what is the ideal to way to integrate websockets in NextJs 14,
I am willing to use any library for websockets, not just socket.io, better if type safe.
I am willing to use any library for websockets, not just socket.io, better if type safe.
Answered by American black bear
maybe, this will help: https://socket.io/how-to/use-with-nextjs
19 Replies
American black bear
I don't think it's next.js related
you need to use websockets on client components
so really, it's just react
@American black bear you need to use websockets on client components
Allen's HummingbirdOP
no, I mean how to use on server side
American black bear
hmm, I don't really think you can
Allen's HummingbirdOP
:(
so I have to host another server for websocket communication ?
American black bear
maybe, this will help: https://socket.io/how-to/use-with-nextjs
Answer
American black bear
if you're trying to run socket on next.js it self
IDK
never needed to run sockets on next.js
Allen's HummingbirdOP
I am trying to make a chatapp
American black bear
well, I think you should keep a seperate server for socket io
@Allen's Hummingbird I am trying to make a chatapp
if you host on vercel, you cannot host ws because ws is fundamentally incompatible with serverless, so you need a separate ws server
if you self-host with your own server then follow the link above
if you self-host with your own server then follow the link above
Allen's HummingbirdOP
wow
why so less support for websockets
@Allen's Hummingbird why so less support for websockets
vercel's architecture is not compatible with ws because serverless is on-demand short-lived lambda, while ws requires a long running server. get your own vps and host ws there
this is not a problem with nextjs. you cannot host ws on vercel regardless of what framework, or the lack thereof, that you use
Allen's HummingbirdOP
alright 👍