rikulo / socket.io-dart Goto Github PK
View Code? Open in Web Editor NEWsocket.io-dart: Dartlang port of socket.io https://github.com/socketio/socket.io
Home Page: https://quire.io
License: MIT License
socket.io-dart: Dartlang port of socket.io https://github.com/socketio/socket.io
Home Page: https://quire.io
License: MIT License
Running "flutter pub get" in Example...
Because socket_io_client >=2.0.0-beta.3-nullsafety.0 depends on socket_io_common ^2.0.0-beta.1-nullsafety.0 and socket_io 1.0.0 depends on socket_io_common ^1.0.0-nullsafety.1, socket_io_client >=2.0.0-beta.3-nullsafety.0 is incompatible with socket_io 1.0.0.
And because no versions of socket_io match >1.0.0 <2.0.0, socket_io_client >=2.0.0-beta.3-nullsafety.0 is incompatible with socket_io ^1.0.0.
So, because nearline depends on both socket_io ^1.0.0 and socket_io_client ^2.0.0-beta.3-nullsafety.0, version solving failed.
Both server and client libraries depends on socket_io_common
with different versions.
IO.Socket socket = IO.io('http://94.130.180.124:8080/', <String, dynamic>{
'transports': ['websocket'],
'autoConnect': true,
});
void testSocket(){
socket.connect();
print('Socket connected');
socket.emit('test', 'Socket test');
socket.on('received_test', (data){
print('--Test received--');
print(data);
})
}
when I use http://localhost:8080/ , socket is working well.
But when I use http://94.130.180.124:8080/, I can't receive response data.
Backend source code of above two links are same.
Please help me.
Add support for Windows, mac and Web
hi,
is it possible to connect securely from client via https?
or can we connect via client with secure:true and proxy via caddy or nginx to non secure server?
thank you
What is the difference between these 2 projects?
Thanks.
can you please upgrade this awesome package to v3
Latest versions of socket io server and client are incompatible with each other. My IO server on JS side is ^4 hence I need to use socket_io_client: ^2.0.0-beta.2 for compatibility. But I want to test my dart client by mocking the server at dart side using socket_io (dev dependency would also do). How can I achieve this.? Apart from the version issues, suggestions on good practice to test sockets locally in dart whose actual server resides on JS, would be appreciated .
Thanks.
Rushabh.
Is there any way to attach this to say, a shelf instance? I want to be able to serve the SPA to the client while also simultaneously handling Socket.IO traffic.
Hello!
I was wondering why didn't you publish your libs to https://pub.dartlang.org ?
It would be easier to reuse in a Dart project.
Hello, I just want to know what happen if a client event take a long time to process, will that delay others, block them or process it anyway ? Do I need to use async as much as I can to avoid that ?
Flask on Python offer a multi-threaded server but I don't know if the Dart implementation offer the same functionnality
Thank you !
I was using socket_io: ^1.0.1 and keep on getting this error
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/stream-3.0.2+1/lib/stream.dart:24:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export "package:rikulo_commons/browser.dart" show Browser; package:rikulo_commons/browser.dart:1
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/stream-3.0.2+1/lib/src/rsp_util.dart:110:23: Error: Method not found: 'XmlUtil.encodeNS'.
str = XmlUtil.encodeNS(str, pre: pre)
I can't seem to be able to build the project
Can you use socket_io_common 2.0.0 and add another version as it is throwing dependency conflict with pre release socket_io_client.
Hello, I have a question, how can I use version 1.0.1 of socket.io and version 2.0.1 of socket_io_client to do a socket communication, furthermore if I use nodejs socket.io how to do a socket communication with socket_io_client ?
Hi
I am using socket_io_client library in my flutter mobile app to build chat app. I am able to connect and chat with socket connection with local url but when I use development url it gives below error in socket.OnConnectionError -
WebSocketException: Connection to 'http://x.xxx.xxx.xx:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket
Please help me out.I am stuck at this
Thank you
Tried this package for the first time with the given example code but couldnt get it working. Is there something wrong i am doing?
I dont understand what the problem is.
import 'package:socket_io/socket_io.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;
void main(){
var io = Server();
io.on('connection', (client) {
print('connection default namespace');
client.on('msg', (data) {
print('data from default => $data');
client.emit('fromServer', "ok");
});
});
io.listen(3000);
// Dart client
IO.Socket socket = IO.io('http://localhost:3000');
socket.on('connect', (_) {
print('connect');
socket.emit('msg', 'test');
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) => print(_));
}
2020-08-06 21:08:02.216756:stream:0
INFO: Rikulo Stream Server 2.5.1 starting on 0.0.0.0:3000
Home: /mnt/DATA/Flutter/musync/lib/services
connection default namespace
2020-08-06 21:08:02.289317:stream:1
SHOUT: 2020-08-06 21:08:02.289054:Bad state: Header already sent
#0 _HttpResponse.statusCode= (dart:_http/http_impl.dart:858:35)
#1 PollingTransport.doWrite.<anonymous closure> (package:socket_io/src/engine/transport/polling_transport.dart:269:11)
#2 PollingTransport.doWrite (package:socket_io/src/engine/transport/polling_transport.dart:302:14)
#3 PollingTransport.write (package:socket_io/src/engine/transport/polling_transport.dart:246:5)
#4 PollingTransport.send.<anonymous closure> (package:socket_io/src/engine/transport/polling_transport.dart:235:12)
#5 PacketParser.encodePayload.<anonymous closure> (package:socket_io_common/src/engine/parser/parser.dart:212:22)
#6 PacketParser.map.<anonymous closure> (package:socket_io_common/src/engine/parser/parser.dart:229:25)
#7 _rootRunUnary (dart:async/zone.dart:1198:47)
#8 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#11 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#12 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#13 Future.wait.<anonymous closure> (dart:async/future.dart:410:22)
#14 _rootRunUnary (dart:async/zone.dart:1198:47)
#15 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#16 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#17 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#18 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#19 Future._complete (dart:async/future_impl.dart:519:7)
#20 new Future.microtask.<anonymous closure> (dart:async/future.dart:201:16)
#21 _rootRun (dart:async/zone.dart:1182:47)
#22 _CustomZone.run (dart:async/zone.dart:1093:19)
#23 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#24 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#25 _rootRun (dart:async/zone.dart:1190:13)
#26 _CustomZone.run (dart:async/zone.dart:1093:19)
#27 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#28 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#29 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#30 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#31 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#32 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
as title.
If I run my angular application without my server running, it continues to attempt to reconnect until I start my server, which is as expected.
But if I don't start my server (my application can mostly function without it) then after a long period of time (I haven't timed it since it tends to happen when my computer is unattended, but I think several hours), there is an exception.
dart_sdk.js:98521 EXCEPTION: Unsupported operation: Infinity STACKTRACE: dart:sdk_internal 11192:44 floor] package:socket_io_client/src%5Cmanager.dart 576:43 get duration package:socket_io_client/src%5Cmanager.dart 494:32 reconnect package:socket_io_client/src%5Cmanager.dart 512:13 <fn> dart:sdk_internal 4077:17 dcall package:socket_io_client/src%5Cmanager.dart 233:17 <fn> dart:sdk_internal 4077:17 dcall package:socket_io_common/src%5Cutil%5Cevent_emitter.dart 52:14 <fn> dart:sdk_internal 10516:11 forEach] package:socket_io_common/src%5Cutil%5Cevent_emitter.dart 51:11 emit package:socket_io_client/src%5Cengine%5Csocket.dart 692:10 onError package:socket_io_client/src%5Cengine%5Csocket.dart 307:28 <fn> dart:sdk_internal 4077:17 dcall package:socket_io_common/src%5Cutil%5Cevent_emitter.dart 52:14 <fn> dart:sdk_internal 10516:11 forEach] package:socket_io_common/src%5Cutil%5Cevent_emitter.dart 51:11 emit package:socket_io_client/src%5Cengine%5Ctransport%5Ctransport.dart 64:12 onError package:socket_io_client/src%5Cengine%5Ctransport%5Cwebsocket_transport.dart 68:9 <fn> dart:sdk_internal 96016:96 <fn> package:angular/src/core/change_detection/..%5Czone%5Cng_zone.dart 156:18 <fn> dart:sdk_internal 30751:14 runUnary package:angular/src/core/change_detection/..%5Czone%5Cng_zone.dart 153:18 [_runUnary] dart:sdk_internal 31004:34 <fn>
The listen method of Server class says it can receive either a number port or http.Server, but it is StreamServer type what expects so I can't pass a Shelf Server object which type is HttpServer.
Any help or suggestion woluld be appreciated.
Calling close on an instance of Server crashes with a ConcurrentModificationError when any clients are connected.
This happens due to removing sockets from the nsps["/"].sockets
list while iterating over it.
As a quick fix for now I came up with following solution:
while (nsps['/'].sockets.length > 0)
{
var socket = nsps['/'].sockets.first;
socket.onclose();
}
Is this a know issue?
Any license to this library?
Hey developers can you plz add web support for this plugin.
can I use http2 in socket io ?
../../../.pub-cache/hosted/pub.dartlang.org/rikulo_commons-4.0.1/lib/src/io/http_wrapper.dart:378:8: Error: The method 'HttpHeadersWrapper.add' has fewer named arguments than those of overridden method 'HttpHeaders.add'.
void add(String name, Object value) {
^
org-dartlang-sdk:///sdk/lib/_http/http.dart:694:8: Context: This is the overridden method ('add').
void add(String name, Object value,
^
../../../.pub-cache/hosted/pub.dartlang.org/rikulo_commons-4.0.1/lib/src/io/http_wrapper.dart:382:8: Error: The method 'HttpHeadersWrapper.set' has fewer named arguments than those of overridden method 'HttpHeaders.set'.
void set(String name, Object value) {
^
org-dartlang-sdk:///sdk/lib/_http/http.dart:703:8: Context: This is the overridden method ('set').
void set(String name, Object value,
^
Process finished with exit code 254
Ive been trying to integrate the socket_io package with alfred but socket_io seems to only allow StreamServers and Alfred implements HttpServer.
Has anyone found a way to integrate both?
socket.io-dart/lib/src/namespace.dart
Lines 223 to 233 in 7fdb760
Hi, I' m using socket_io: ^0.9.0+2 and socket_io_client: ^0.9.4 in my pubspec.yaml file.
When i run my app, i'm getting the following error:
Resolving dependencies... 2,9s
Error reading dependency file D:\Source\Flutter\Mobile\aiqueue\build\app\intermediates\flutter\debug\android-arm\snapshot_blob.bin.d: java.lang.ArrayIndexOutOfBoundsException: 1
Error reading dependency file D:\Source\Flutter\Mobile\aiqueue\build\app\intermediates\flutter\debug\android-arm\snapshot_blob.bin.d: java.lang.ArrayIndexOutOfBoundsException: 1
Compiler message:
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/rikulo_commons-3.2.1/lib/src/io/http_wrapper.dart:9:7: Error: 'HttpRequestWrapper' can't implement both 'Stream<List>' and 'Stream'
FAILURE: Build failed with an exception.
Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 765
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebugArm'.
Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 11s
My flutter doctor results:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel unknown, v1.10.1, on Microsoft Windows [Version 10.0.17763.737], locale el-GR)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] VS Code, 64-bit edition (version 1.38.0)
[√] Connected device (1 available)
• No issues found!
Hey can you please give a example code of joining room and sending messages to specific room ?
Would love to see a null safe version of this library. If I have some time I'll look into a PR.
The error was:
type '(Socket) => Null' is not a subtype of type '(dynamic) => dynamic'
On this line:
io.on('connection', (Socket client) {
Any date to make it Dart 2 compatible?
After import 'package:socket_io/socket_io.dart', This error occurred
The current code doesn't give the ability to the developer to wait for httpServer initialization or close. StreamServer returns a Future after such methods are called, but they are not used in this SocketIO port.
I will submit a PR that fixes this issue.
when I implement the socket it listens to my event and receives the message twice, when I leave and re-enter the view it receives the message 4 times and so on in pairs. At first I thought it was a bad implementation by my server, but I tested it with soclet.io-client for Angular and the behavior when I send a message is correct.
Would this work with flutter for making mobile apps?
When using this server (v1.0.0) with socket.io-client-dart (v1.0.1) an exception is thrown when making a connection. This happens because the socket is upgraded to a Websocket socket via its transport and the payload is sent, but the polling transport tries to send the packet again.
Stacktrace:
SHOUT: 2021-09-02 16:22:59.467450:Bad state: Header already sent
#0 _HttpResponse.statusCode= (dart:_http/http_impl.dart:1188:35)
#1 PollingTransport.doWrite.<anonymous closure> (package:socket_io/src/engine/transport/polling_transport.dart:270:13)
#2 PollingTransport.doWrite (package:socket_io/src/engine/transport/polling_transport.dart:306:14)
#3 PollingTransport.write (package:socket_io/src/engine/transport/polling_transport.dart:245:5)
#4 PollingTransport.send.<anonymous closure> (package:socket_io/src/engine/transport/polling_transport.dart:234:12)
#5 PacketParser.encodePayload.<anonymous closure> (package:socket_io_common/src/engine/parser/parser.dart:212:22)
#6 PacketParser.map.<anonymous closure> (package:socket_io_common/src/engine/parser/parser.dart:229:25)
#7 StackZoneSpecification._registerUnaryCallback.<anonymous closure>.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:126:26)
As same as this - https://socket.io/docs/#sending-and-getting-data-(acknowledgements)
Hello all,
Is there any documentation on the protocol version compatibility?
What original features are suported?
Hello,
I would like to ask if when is the next version for this library for Flutter 2.x null-safety support.
I want to run server at specific address, I couldn't find way to achive this..Is this correct way?
import 'package:socket_io/socket_io.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;
void main(){
var io = Server('192.168.43.222'); // this is my expectation
io.on('connection', (client) {
print('connection default namespace');
client.on('msg', (data) {
print('data from default => $data');
client.emit('fromServer', "ok");
});
});
io.listen(3000);
// Dart client
IO.Socket socket = IO.io('http://192.168.43.222:3000'); // set server address to client side
socket.on('connect', (_) {
print('connect');
socket.emit('msg', 'test');
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) => print(_));
}
Hi, thank you for the package!
I want to run several servers on a single host. And I'm facing the following behavior:
I'm running the server:
var io = Server(server: 3004);
And I got the output:
2022-10-14 16:00:12.929658:stream:0
INFO: Rikulo Stream Server 3.0.3 starting on 0.0.0.0:3000
Home: /Users/macbook/flutter/projects/server_io_dart/server_io_dart/bin
2022-10-14 16:00:12.947245:stream:1
INFO: Rikulo Stream Server 3.0.3 starting on 0.0.0.0:3004
Home: /Users/macbook/flutter/projects/server_io_dart/server_io_dart/bin
2022-10-14 16:00:12.947245:stream:1
INFO: Rikulo Stream Server 3.0.3 starting on 0.0.0.0:3004
Home: /Users/macbook/flutter/projects/server_io_dart/server_io_dart/bin
Checking ports:
lsof -i -P -n | grep LISTEN | grep 300
dart 69553 macbook 8u IPv4 0xe009f966273201 0t0 TCP *:3000 (LISTEN)
dart 69553 macbook 9u IPv4 0xe009f9679edcb1 0t0 TCP *:3004 (LISTEN)
They are both busy but why? I typed 3004 for my server.
What am doing wrong?
Because of this, I can't run several servers on a single host. Port 3000 is busy by the first server.
Hi. Thanks for your port.
I see your dart server sample, but how can I install it as server and launch it?
I worked with php websocket server and launch it by terminal with command php myws.php.
I'm new to Dart so I'm sorry if my question seems to be stupid but I haven't found any docs on it.
Thanks in advance.
hi!
I used in app your library, but I have a lot of logs and can do nothing with it:
2021-01-20 14:15:08.225: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:08.227: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:15:13.250: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:15:13.278: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:13.280: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:15:28.228: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:15:28.260: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:28.262: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:15:33.782: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:15:33.815: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:33.817: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:15:48.263: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:15:48.296: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:48.299: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:15:53.818: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:15:53.850: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:15:53.853: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null" 2021-01-20 14:16:08.300: [FINE] [socket_io_client:engine.Socket] writing ping packet - expecting pong within 60000ms 2021-01-20 14:16:08.334: [FINE] [socket_io_client:engine.Socket] flushing 1 packets in socket 2021-01-20 14:16:08.336: [FINE] [socket_io_client:engine.Socket] socket receive: type "pong", data "null"
Can you, please, add option to Socket constructor to set socket io logger level?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.