Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected OnConnect behaviour #1

Closed
loothood opened this issue Oct 28, 2022 · 1 comment
Closed

Unexpected OnConnect behaviour #1

loothood opened this issue Oct 28, 2022 · 1 comment

Comments

@loothood
Copy link

Hi!
First of all, thank you very much for your projects. I mean serverme, packme and connectme. Very helpful.
On the servers side, I'm using serveme, on a client-side - connectme
I'm trying to get onConnect event and give a client id based on this action. So, I'm trying:
client:

import 'package:connectme/connectme.dart';

Future<void> createTestClient() async {
  final ConnectMeClient client =
      await ConnectMe.connect('ws://127.0.0.1:31337');

  //client.send('Hello!');
  client.listen<String>((String message) async {
    print('[CLIENT]: server says: "$message"');
  });
}

Future<void> main() async {
  await createTestClient();
}

server:

import 'package:serveme/serveme.dart';

Future<void> main() async {
  final ServeMe<ServeMeClient> server = ServeMe<ServeMeClient>(
    modules: <String, Module<ServeMeClient>>{
      'mymodule': MyModule(),
    },
  );
  await server.run();
}

class MyModule extends Module<ServeMeClient> {
  int clientNumber = 0;

  @override
  Future<void> init() async {
    server.log(
        'Module initialized'); 
  }

  @override
  void run() {
    server.listen<String>((String message, ServeMeClient client) async {
      log('Got a message: $message');
      client.send(message + '!!!!');
    });

    events.listen<ConnectEvent<ServeMeClient>>(
        (ConnectEvent<ServeMeClient> event) async {
      log('A new client with id: $clientNumber', MAGENTA);
      event.client.send('id:$clientNumber');
      clientNumber++;
    });
  }

  @override
  Future<void> dispose() async {
    server.log('Module disposed');
  }
}

Running server and client. And... nothing happened!
But, If I uncomment line //client.send('Hello!'); on the client side, everything works well.
So, I'm a bit confused about why I have to send some message from the client side to a server to initiate on events.listen<ConnectEvent<ServeMeClient>> event listener?

@loothood loothood reopened this Oct 28, 2022
@loothood
Copy link
Author

That's strange, but everything works now.

@loothood loothood closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant