www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Chatting with a server

How would you chat with a server? This is my naive attempt:

class Client {
   Socket socket;

  Token fetch() {
    ubyte[1024] buffer;  // if more space is needed...
     socket.receive(buffer);
     return decode(buffer);
  }

  void send(Token tkn) {
   ubyte[] buffer = encode(tkn);
   socket.send(buffer);
  }
}

It can send and fetch data (encoded tokens) to/from server. But frequently
I see network clients using a connection pool or an event loop. I descarted
event loops because they looks hard to implement (and libev docs don't let
me anywhere).

Do you can guide me on this trouble?

Pedro Lacerda
Feb 13 2012