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

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.