reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.
https://reactphp.org/socket/
MIT License
1.2k stars 156 forks source link

Interactive client example? #291

Closed bilogic closed 2 years ago

bilogic commented 2 years ago

Hi,

I'm having trouble writing "elegant" code for an interactive client, i.e. imap client, IRC client

Specifically, I find it very hard to write in a way that makes sense which is the 1st step, which is 2nd etc due to the reactive/event driven nature, e.g.

  1. Login
  2. If login success, select a mailbox/join a channel
  3. Then check how many messages there are/who is in the chat group

Most of the samples are a 1 transaction protocols like HTTP and I can't see any that applies the concepts of await etc

Possible to make a simple example, say POP3? Thank you!

SimonFrings commented 2 years ago

Hey @bilogic

I don't know if I understand you correctly but if your looking for a interactive communication via CLI, you should take a look at clue/reactphp-stdio. @clue also has a project that sounds similar to yours: clue/reactphp-quassel.

Hope this will help you as a first step to move on. Let me know if you have any further questions!

bilogic commented 2 years ago

Hey thanks!

Doesn't have to be interactive, it's more like how to make it not take the next steps until the earlier has succeeded, e.g. don't select a mailbox until login is complete. Sometimes multiple such sequential steps are needed and it makes my code quite unreadable, let alone testable.

I'm trying to get something going with https://github.com/shuchkin/react-smtp-client, let me take a closer look at your suggestions. Thank you.