Coder Social home page Coder Social logo

bsonnetwork's Introduction

BsonNetwork

networking as easy as making a dictionary

BsonNetwork seeks to provide a very simple solution for application networking. Using the new BSON standard, BsonNetwork allows client applications to open connections and trade BSON documents (dictionaries!) around.

For now, BsonNetwork is only in Objective-C, enabling Macs and iPhones to talk to each other by trading NSDictionaries. I plan to add the (trivial) python implementation soon.

Usage

BsonNetwork consists of two classes:

BNServer

Use BNServer to manage and/or to listen for incoming connection, like so:

BNServer *server = [[BNServer alloc] init];
server.delegate = self;

if (![server startListeningOnPort:31688]) {
  // oh uh. listening failed.
}

[server connectToAddress:@"localhost:31688"];
// yes, we can connect to ourselves

Then, when the BNConnection successfully connects, BNServer will call the delegate. Here we are greeting ourselves:

- (void) server:(BNServer *)server didConnect:(BNConnection *)conn {

  conn.delegate = self; // From now on, we'll receive the messages.
  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  [dict setValue:@"Hello World!" forKey:@"greeting"];
  [conn sendDictionary:dict];

}

Note that BNServer will call @selector(server:didConnect:) for both incoming and outgoing connections.

BNConnection

You can even use BNConnections without a BNServer:

BNConnection *conn = [[BNConnection alloc] initWithAddress:@"localhost:31688"];
conn.delegate = self;
[conn connect];

And in turn, BNConnection will call its delegate when it changes state:

- (void) connectionStateDidChange:(BNConnection *)conn {
  switch (conn.state) {
    case BNConnectionConnected:
      // we're connected!;
      break;

    case BNConnectionDisconnected:
      // Oh no, we disconnected!
      break;
  }
}

And when it receives data:

- (void) connection:(BNConnection *)conn receivedDictionary:(NSDictionary *)dict {
  if ([[dict valueForKey:@"greeting"] isEqualToString:@"Hello World!"]) {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"Why Hello!\nWith love,\nThe World" forKey:@"response"];
    [conn sendDictionary:dict];
  }
}

Install

Latest Release

  • download release/BsonNetwork.tar.gz and untar.
  • put BsonNetwork.framework* in your project.
  • add (existing apple framework) CFNetwork.framework to your project.
  • Note: iPhone developers, do not worry. This .framework is not dynamically linked, it is a static library bundled as a framework for ease of use. I've already submitted apps with libraries bundled the same way. I'll update once BsonNetwork is live in an app.

Building the Source

  • clone the repository
  • open the xcode project
  • select the Build Framework target
  • build for both Device Release and Simulator Release.

License(s)

BsonNetwork Licence

The BsonNetwork source is released under the MIT License, copyright 2010 Juan Batiz-Benet. The source is available at http://github.com/jbenet/bsonnetwork

Libraries in use:

Libraries that were being used, or will potentially be used:

TODO:

  • Write usage examples and docs.
  • Write objc bounce test server using BNServer
  • Write python implementation.
  • Figure out why NuBSON sometimes fails to provide correct data. (Did key sorting break something?)

bsonnetwork's People

Contributors

jbenet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.