-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md.backup
43 lines (35 loc) · 1.49 KB
/
README.md.backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Next.js Chat App
## 🚀 Initial Implementation with Socket.io WebSockets and Supabase Data
This chat application leverages Socket.io for real-time communication and Supabase for data management.
### **📡 Socket.io Communication Flow**
* __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.
``` javascript
// 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.
``` javascript
// Client-side example
socket.on('message', (data) => {
console.log('Received message:', data);
});
// Server-side example
socket.on('update', (data) => {
console.log('Received update:', data);
});
```
## 🔄 Summary of Socket.io Functions
* **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).