Skip to content

The Socket.IO plugin for the Flutter.

License

Notifications You must be signed in to change notification settings

simkosal/socket_io

 
 

Repository files navigation

socket_io

The Socket.IO plugin for the Flutter.

Donate

Getting Started

For help on editing plugin code, view the documentation.

Example

Client

Code

const uri = 'http://192.168.1.38:8080';
final socket = await SocketIO.createNewInstance(uri);
await socket.on(SocketIOEvent.connecting, () async {
  print('Connecting...');
});
await socket.on(SocketIOEvent.connect, () async {
  print('Connected.');

  final id = await socket.id;
  print('Client SocketID: $id');
});
await socket.on(SocketIOEvent.connectError, (error) {
  print('Error: $error');
});
await socket.on('sayHello', (greeting) {
  print('Hello, ${greeting['Hello']}');
});
await socket.connect();
await socket.emit('sayHello', [
  {'Hello': 'world!'},
]);

Log

I/flutter: Connecting...
I/flutter: Connected.
I/flutter: Client SocketID: ska0utZ3GlmA8cC6AAAA
I/flutter: Hello, world!

Node.js Socket.IO Server:

Code

const app = require('express')();
const server = require('http').Server(app);
const io = require('socket.io')(server);

io.on('connection', (socket) => {
  console.log(`Client SocketID: ${socket.id}.`);
  socket.emit('sayHello', {Hello: 'world!'});
  socket.on('sayHello', (greeting) => {
    console.log(`Hello, ${greeting['Hello']}`);
  });
});

server.listen(8080);

Log

Client SocketID: ska0utZ3GlmA8cC6AAAA.
Hello, world!

About

The Socket.IO plugin for the Flutter.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 43.8%
  • Kotlin 28.8%
  • Ruby 18.9%
  • Swift 6.1%
  • Objective-C 2.4%