What is the use of path for socket.io, how is that different from custom namespace #4679
-
const socket = io('http://myserver/admin', { Or under what circumstance do I need to set custom path? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi! The
The
Reference: https://socket.io/docs/v4/client-options/#path On the other hand, the namespace (the Reference: https://socket.io/docs/v4/namespaces/ With Reference: https://socket.io/docs/v4/socket-io-protocol/#format |
Beta Was this translation helpful? Give feedback.
Hi! The
path
option refers to the request path. Withpath: '/mypath'
, you will see in your network panel HTTP requests like:The
path
option defaults to/socket.io/
:Reference: https://socket.io/docs/v4/client-options/#path
On the other hand, the namespace (the
/admin
in your example) is the part of your application you'd like to connect to. It provides a way to split your application logic into independent modules, while using the same WebSocket connection under the hood (multiplexing).Reference: https://socket.io/docs/v4/namespaces/
With
io('http://myserver/admin')
, you reach to/admin
namespace, withio…