Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
### Server-Side (Node.js with Socket.IO)
1. **Install Dependencies**:
- In your Node.js project hosted on Appwrite, install the `socket.io` package:
```bash
npm install socket.io
```
2. **Create the Socket.IO Server**:
```javascript
// server.js
const { createServer } = require('http');
const { Server } = require('socket.io');
// Create an HTTP server (using Appwrite's server)
const httpServer = createServer();
const io = new Server(httpServer);
io.on('connection', (socket) => {
console.log('Client connected:', socket.id);
// Handle custom events
socket.on('message', (data) => {
console.log('Received message:', data);
// Broadcast the message to all connected clients
io.emit('message', data);
});
// Handle disconnection
socket.on('disconnect', () => {
console.log('Client disconnected:', socket.id);
});
});
// Start the server
const PORT = process.env.PORT || 8080;
httpServer.listen(PORT, () => {
console.log(`Socket.IO server listening on port ${PORT}`);
});
```
### Client-Side (Flutter with socket_io_client)
1. **Add Dependencies**:
- In your Flutter project, add the `socket_io_client` package to your `pubspec.yaml`:
```yaml
dependencies:
socket_io_client: ^2.1.0
```
2. **Connect to the Server**:
```dart
import 'package:flutter/material.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final IO.Socket socket = IO.io('https://your-appwrite-hosted-server.com', <String, dynamic>{
'transports': ['websocket'],
});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Socket.IO Example')),
body: Center(
child: ElevatedButton(
onPressed: () {
socket.emit('message', 'Hello from Flutter!');
},
child: Text('Send Message'),
),
),
),
);
}
}
```
3. **Handle Server Messages**:
- Listen for messages from the server:
```dart
socket.on('message', (data) {
print('Received from server: $data');
});
```
4. **Run Your App**:
- Deploy your Node.js server to Appwrite.
- Run your Flutter app (`flutter run`).
Now your Flutter app can communicate with your Appwrite-hosted Node.js server using Socket.IO. Customize the events and data as needed for your application! 🚀
Remember to handle error cases, authentication, and other features specific to your use case. Happy coding! 😊
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team