Sign in to follow this  
  • entries
    25
  • comments
    27
  • views
    13990

Network Stuff

Sign in to follow this  

273 views

Over the past couple of days I've been looking at some low-level network APIs(so this disregards behemoths like Raknet, etc), in an attempt to find something to start using for a remote debugger/python interface(sorta like a remote telnet session for any projects I may be working on). So obviously step #1 is to find a decent-enough network API for the job, and I vetted three... and eventually chose HawkNL. The reasons being: 1, I have an irrational fear of MS APIs, so WinSock2 was out of the question. And 2, SDL_net documentation is not quite so informative as is necessary. Also, HawkNL won't block on any method, and so didn't require me to write messy multithreading code, which is nice :)

As I started designing an interface for providing a Python interface over a socket, it became pretty obvious that a layer of abstraction over HawkNL was required... so I did what everyone should do.. wrap wrap wrap :D

The interface I've ended up with is quite simple, and doesn't try to do to much, which is usually a problem with any code written for public use.. it tries to do too much. So yeah, it's pretty slim,.. and non-blocking =)

Obviously different applications will have different ways of sending their data, some send it in plain text(ie, IRC), others, it's usually binary data(HTTP,Games). Initially the data goes from the HawkNL wrapper, to the SocketEventManager class, which will process the stream of raw data into a usable form. When it has gather enough raw data to be interpreted(ie, reaching a \n for IRC), the SEM will inform the NetworkEventManager, with news of a chunk of data which can now be processed. I figured two types of SEM would be useful:

1) A plain-text SEM, for text-based protocols, which informs the NEM when a full line of text has been recieved.

PlainTextSEM -> PlainTextNEM

2) A packet SEM, which will identify registered packets by a 2byte ID, and wait until the entire packet is in the buffer before notifying the NEM.

PacketSEM -> PacketNEM

The wrapper only requires that a class be registered with a Socket using a SEM interface, it does not require that a NEM be used, but as the PlainTextSEM and the PacketSEM would be bundled with the HawkNL wrapper, in order to prevent people from having twiddle with the innards of these classes, a NetworkEventManager has been added, to respond to events such as a line of text or complete packet being recieved.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now