Giter VIP home page Giter VIP logo

socket.io-dart's People

Contributors

felangel avatar guilhermecaldas avatar indatawetrust avatar jodinathan avatar jumperchen avatar nicobritos avatar thinkdigitalsoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socket.io-dart's Issues

Server's example code doesn't work?

The error was:

type '(Socket) => Null' is not a subtype of type '(dynamic) => dynamic'

On this line:

    io.on('connection', (Socket client) {

Bad state: Header already sent when upgrading to a Websocket connection

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)

Use with webserver

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.

Can't build for dart 2.8.1

../../../.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

Add logging level into socket constructor

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?

... how to use it as 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.

socket_io: ^1.0.0 Incompatible with socket_io_client: ^2.0.0-beta.2

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.

Server doesn't wait for httpServer to start or close

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.

socket.io 1.0.1 and socket_io_client 2.0.1

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 ?

Room example

Hey can you please give a example code of joining room and sending messages to specific room ?

SHOUT : Bad state: Header already sent with Example code

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.

The code run:

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(_));
}

Logs:

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)

Licence

Any license to this library?

Integration with Alfred Framework

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?

Best practice when dealing with a lot of users

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 can't connect to http server with this package in iOS.

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.

Can't add both server and client library.

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.

Change Server port

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.

Exception after a large number of failed connection attempts

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>

Can't set specific ip address to server

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(_));
}

Shelf integration

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.

Null safety support

Hello,

I would like to ask if when is the next version for this library for Flutter 2.x null-safety support.

Compile error

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'

  • 'Stream' is from 'dart:async'.
  • 'List' is from 'dart:core'.
  • 'Uint8List' is from 'dart:typed_data'.
    class HttpRequestWrapper extends StreamWrapper<List> implements HttpRequest {
    ^
    /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/stream-2.2.1/lib/src/connect_impl.dart:249:7: Error: '_ReUriRequest' can't implement both 'Stream<List>' and 'Stream'
  • 'Stream' is from 'dart:async'.
  • 'List' is from 'dart:core'.
  • 'Uint8List' is from 'dart:typed_data'.
    class _ReUriRequest extends HttpRequestWrapper {
    ^
    Compiler failed on D:\Source\Flutter\Mobile\aiqueue\lib\main.dart

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!

Null safety error

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

[BUG] Calling close on Server raises ConcurrentModificationError

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?

Null safety

Would love to see a null safe version of this library. If I have some time I'll look into a PR.

secure connection from client

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

Socket.io message event firing multiple times

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.