This chat application leverages Socket.io for real-time communication and Supabase for data management.
- socket.emit ➡️ Send Data
- From: Client or Server
- To: Server or Client
- Usage: socket.emit is used to send data to the server or from the server to the client. This method allows for initiating communication from either the client or the server side.
// Client-side example
socket.emit('message', { user: 'John', message: 'Hello, world!' });
// Server-side example
socket.emit('update', { status: 'New user connected!' });
-
socket.on ⬅️ Receive Data
- From: Server or Client
- To: Client or Server
- Usage: socket.on is used to listen for data sent from the server or client. This allows both the client and server to react to incoming messages or events.
// Client-side example
socket.on('message', (data) => {
console.log('Received message:', data);
});
// Server-side example
socket.on('update', (data) => {
console.log('Received update:', data);
});
-
socket.emit:
- Function: Sends data or events.
- Direction: Bidirectional (Client ➡️ Server or Server ➡️ Client).
-
socket.on:
- Function: Listens for incoming data or events.
- Direction: Bidirectional (Client ⬅️ Server or Server ⬅️ Client).