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.

Sunday, August 5, 2012

SQLite wrapper based on java.lang.reflect

In Android development, data persistence is often realized with SQLite. Sometimes the act of preparing all the classes, the adapter, every kind of query (CRUD) and rewrap into model,is a bit frustrating. It's like something already done, to do again every time.

I never see this kind of class on the web, so I decided to make my own one.
What I'm talking about?

A class that simplifies the common use of SQLite with a friendly usage (inspired by .NET's LINQ one).
SQL Scripts are defined by the model, so you need to supply the object instance or just its class.

For the moment I provided:
  • select (distinct, count,where, limit, order by)
  • delete (where)
  • insert
  • transactions