What is the order of functions called?
These will only be called when a connection is made (though a connection which is attempted will also call a few before it fails).
With a client
EM.connect( '127.0.0.1', port, EchoClient?)called firstinitializemethod (called by EM on a new instance—currently without any parameters and only internally)post_init(always called)- block given to
EM.connect(always called) connection_completed(called on success, else unbind)receive_data(called by EM—when it receives incoming data and it’s that port’s turn to process it—it will pass it “all or most” of incoming data).send_data,send_file_data,send_datagramcalled by you—puts those things in EM’s outbound queue for that connection.close_connection,close_connection_after_writing,EM::(stop | stop_event_loop)all shut it down (called by you).unbind
With a server (only on incoming connections, once per connection):
initializepost_init(called by EM)EM.start_serverblock (the block you passed to the start server call, called by EM)send_data/send_file_data/send_datagram(called by you)receive_data(called by EM)stop_server(called by you — stops server from listening, though existing connections are still live) — see documentationclose_connection,close_connection_after_writing,EM::(stop | stop_event_loop)all shut it down (called by you).unbind(when socket closed) (called by EM, whenever it closes because of you or the connecting peer)
Which are the methods you can redefine, then, that gets called?
post_init, receive_data, unbind, and, for clients, connection_completed.
What if I have a server connect to a client on the same host running within the same EM—which one gets executed first? From experimentation, it appears to be post_init(client), client block, post_init server, server block, connection_completed(client), then unbind of the one that makes the first call to close_connection (i.e. if server calls close_connection, its unbind is called first [right then?], then the clients’).