Simple TCP message framework

P

Padawan Learner

Seems like the following pattern must be very common, solved a million
times, but I can't seem to find anything this simple and ready to use.
Basically I just want a simple python messaging layer that hides some of
the messiness of the underlying sockets and user authentication. It
would be asyncore under the hood of course.

Perhaps what I am looking for is hiding in plain sight, but there are so
many asynchronous communication tools out there, it's hard to thumb
through them all. So I'm not looking for such a list of toolkits to
browse through. Just something simple that does the equivalent of the
following:

Server:
on_open(user) - called when a user logs in
on_close(user) - called when a user disconnects
on_recv(user, s) - called when a user sends a message
send(user, s) - send a message to a user

Client:
open(host, user, password) - open an authenticated session with the
host
close() - disconnect
send(s) - send a message to the server
on_recv(s): called when a message is received from the server

Methods starting with "on_" are callbacks intended to be implemented by
derived classes.

Messages are atomic and delimited by '\n'. So concatenation of buffered
messages is hidden. A message is received when complete (i.e. terminated
with '\n'). Also, each message should be implicitly flushed, so that it
will be received in a timely manner in the absence of additional messages.

Extra bonus for a compatible javascript implementation of the Client as
well, so it can run in a browser.

Thanks in advance for any thoughts.
- Padawan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top