Showing posts with label open source. Show all posts
Showing posts with label open source. Show all posts

Wednesday, August 8, 2012

String-based Socket communication classes

I recently removed an old post called "A little framework for TCP client-server communication".

That's why I think it was not so clear and useful.
Today I propose the "engine" I used.

I used those libs for some projects like:
  • A push server for Android clients
  • A server that controls some computer's feature like volume, services, tasks, also file exchange
  • A computer's mouse controller
  • Data exchange between two different processes

I think it's very useful, scalar and powerful for simple projects.

It's basically composed by two class and two interfaces.

class Server: wraps a ServerSocket object and manages incoming client connections, and messages through an interface called OnServerEventsListener.
interface OnServerEventsListener: defines some standard events like, adding a client, receiving messages, receiving errors of Server or from Clients.
class Client: wraps a Socket object and manages a simple communication through an interface called OnClientEventsListener.
interface OnClientEventsListener: defines events like connecting, disconnecting, on receiving message, on exception generated.