Namespace
Namespaces
Namespaces provide logical separation of features and event handling within the SocketIO server. They allow different parts of an application to operate independently using a single physical connection.
Default Namespace
If a client connects without specifying a namespace, it is attached to the default namespace ("").
Configuration config = new Configuration();
config.setPort(9092);
SocketIOServer server = new SocketIOServer(config);
// default namespace exists implicitly
server.start();Custom Namespace
Custom namespaces separate application concerns and event scopes.
SocketIOServer server = new SocketIOServer(config);
Namespace chat = server.addNamespace("/chat");
Namespace admin = server.addNamespace("/auth");
server.start();Each namespace defines:
its own event listeners
its own connection lifecycle
its own authorization logic
its own broadcast operations
Public Namespace Example (/chat)
/chat)The /chat namespace is open and allows general messaging without authentication.
Server
Client
Authenticated Namespace Example (/auth)
/auth)The /auth namespace restricts access using authorization logic executed during connection.
Server
Authorized Client
Unauthorized Client
Expected server output:
Last updated
Was this helpful?