https://github.com/influx6/socketful
awesome socket api for both client and server side
https://github.com/influx6/socketful
Last synced: about 2 months ago
JSON representation
awesome socket api for both client and server side
- Host: GitHub
- URL: https://github.com/influx6/socketful
- Owner: influx6
- License: other
- Created: 2014-09-13T21:12:06.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-09-25T18:15:57.000Z (about 11 years ago)
- Last Synced: 2025-07-21T10:51:13.405Z (3 months ago)
- Language: Dart
- Size: 152 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Socketful
==========
Provides a simple extendable websocket api for both client and server##Example:
Client Side:
```
var socks = Socketful.create({
'url':'ws://127.0.0.1:3000/',
});-> SocketStores are created where sockets belonging to a specified routes are allocated and by listening to those stores we can customize each sockets behaviour as needed
var records = socks.of('/records');
-> Simply listen to a store and add the behaviours and messages that a client side socket is to send to the server and its behaviour and your ready
records.listen((bridge){
bridge.onSend.listen(Funcs.tag('bridge-outtransmission'));
bridge.onReceive.listen(Funcs.tag('bridge-intransmission'));var buffer = bridge.watch('buffer');
var server = bridge.watch('end:shutdown');
buffer.listen(Funcs.tag('buffer-transmission'));bridge.send('ping','ping');
bridge.send('drill',{'name':'london'});
bridge.send('buffer',[12,323,32,32]);server.listen((m){
print('closing socks');
socks.close();
});bridge.send('end:server',0);
});```
Server Side:
The server side as with the dart:io provides websocket implementations for doing server side request and creating server websockets to handle websocket requests from clients and socketful supports both.
Server-Side Requests:
```
Socketful.attachURI('ws://127.0.0.1:3000/records').then((record){
var pong = record.watch('ping');
var buffer = record.watch('buffer');
var end = record.watch('end:shutdown');end.listen((f){
if(Valids.asserts(f['data'],1))
return record.close();
});buffer.listen((f){
//received messages under buffer tag
});pong.listen((f){
//received messages under ping tag
});//send messages to the server from these socket
record.send('ping','ping');
record.send('buffer',['shell sock']);
record.send('end:server',0);```
Server-Side Websocket Server:```
-> We create a server dedicated for websocket connections, though if desired,socketful on the server provides the attachRequests method that allows per request handling,incase one desires to only bind a namespace of a route only to socketfulSocketful.attachAddress('127.0.0.1',3000).then((socks){
//the routes for websocket connections
var f = socks.of('/records');//watch for messages based on tags
var ping = f.watch('ping');
var buffer = f.watch('buffer');
var server = f.watch('end:server');//respond to these messages
ping.listen((m){
f.send('ping','pong');
});buffer.listen((m){
f.send('buffer','recieved');
});server.listen((m){
f.send('end:shutdown',1);
});});
```