Showing posts with label socket. Show all posts
Showing posts with label socket. 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.

Sunday, March 11, 2012

A little framework for TCP client-server communications (part2)

Here we are for the second part of this article.  I remeber to everybody that this little framework is not created for market, distrubution or diffusion. (Not even for best practices)

Let's start with some example code!

On the base of what I wrote in the first part, let' see how to create a simple server with JRR Framework.

ResponseManager server = new ResponseManager(8888); //8888 is the listening port
server.setConsoleLogEnabled(true); //enable printing log on the console
server.start(); //start listening

Wednesday, February 29, 2012

A little framework for TCP client-server communications (part1)

Hello world! I'm back from work and now it's time for requiem... :)

Today I wanna talk about a little framework written in Java for managing tcp/ip sockets connections.
Why I need a framework such this and what can I do with this framework ?

Remember that a good framework is very useful if can save you a lot of time/money on writing a lot of code. I think that JRR (Java Request Response) has a big potential and if you have to write an application,on every kind of device that supports internet, you should try it and see how it's simple to manage it all

Zooming out on features: with JRR you can:

  • Enstablish a Server that listens on a port; Provide your own implementation of handling client messages and server response. Also manages timeouts.
  • Create a Client that send requests to server, and handles response, exceptions, connection timeout and custom response timeout. 
P.S. If you don't provide your implementation, classes have their own.

Want to know more? Keep scrolling this post...

Thursday, January 5, 2012

Server Multi-client in C# .NET

Un altro progetto a scopo didattico che è sempre carino da affrontare è la comunicazione Client/Server via socket TCP.

E cosa schiarisce meglio le idee di un immagine?

Il progetto in questione si divide quindi in due parti. La prima è semplicemente un server, realizzato in c# .net, che:
-riceve in ingresso delle stringhe formattate in un certo modo,
-effettua un operazione a seconda di che stringa riceve,
-rimanda al client la risposta in formato stringa.

Questo tipo di progetto può avere numerosissimi tipi di applicazione: in teoria tutto quello che può fare un applicativo .Net è "attivabile/reperibile" via socket. Le più stupide modalità di utilizzo che mi vengono in mente ora possono essere: reperire dei dati da un database, lanciare procedure, controllare funzioni di sistema ecc... ecc... 

Vediamo un po' più nel dettaglio come funziona.