<< String 2006 | Home | Scheduling Algorithms for Procrastinators >>

Joost: A Simple Networking Library

Today's OCI C++ lunch features Justin Michel presenting his own networking library—Joost. It abstracts away many of the lower level details and makes network programming simple and correct. The Joost abstraction retains only a few concepts: addresses, connections, events, messages. Hook them up and you've got a little thingy that will do the right things with little programmer attention. Things are done in an asynchronous fashion and nothing blocks. Flow control are handled through events.

The interfaces are carefully designed to make efficient implementations possible on multiple platforms and across programming languages. .NET and Java implementations have been done. C++ implementation is in progress.

Here's a snippet of client code:

class hello_client : public joost::tcp_events {
//...
public:
  void run() {
    joost::ip_address addr("localhost", 5555);
    joost::message_size_decoder_ptr no_msd;
    joost::tcp_events_ptr handler(this, dont_delete);
    joost::tcp_connection con(addr, no_msd, handler);

    std::string hello = "Hello World";
    joost::out_message out;
    out.append_uint8(hello.size() + 1); // size of string + 1 byte header
    out.append_ascii(hello);

    std::cout << "\nSending Hello..." << std::endl;
    joost::tcp_send_results result = con.send(out);

    std::cout << "\nDisconnection..." << std::endl;
    con.disconnect();
    hman.wait();
    std::cout << "\nDone." << std::endl;
  }

// ...
};



Add a comment Send a TrackBack