Skip to content Skip to sidebar Skip to footer

Tablet(iPad/Android)-Server Communication Protocol

I am going to build a client-server application. The client here is an iPad (or an android-based) tablet. The server is a normal pc. Both the clients and the server are connected t

Solution 1:

The answer depends by what you define by "server", "client", and "protocol".

Technically, the answer is "yes"; from a practical standpoint the framework you are looking for is called "socket", but regarding the protocol things may get complicated.

A protocol is a syntax structure governing data exchange, i.e., a set of rules you use to request/provide a service (see the IETF website for a list of standard ones). Sockets, on the other hand, provide you merely a communication channel to bring bytes from one side to another and, on top of which, you are required to implement the protocol. The good news is that socket are language independent and you can send messages between heterogeneous devices (ipad/android/linux/windows).

Using sockets in java is easy (I am making it very short here)

server side

ServerSocket ss = new ServerSocket(port);
Socket s = ss.accept();
InputStream is = s.getInputStream();

client side

Socket s = new Socket("server.address", port); // same port as above
OutputStream os = s.getOutputStream();

When you write something using os.write() the same bytes will be read by is.read(). What you write on os is the implementation of your protocol.

This topic is covered (for java language) quite well by "Thinking in Enterprise java" by Bruce Eckel, you can access the digital edition for free. In C/C++/Objective C things are more complicated but you can easily google for tutorials.

Each service defines its own protocol and you should decide if one of the existing will do or you have to define your own, depending on which service you want to implement between the two devices.

If, as in the standard approach, the PC plays the role of server and clients want to retrieve information from it, you might want to consider installing a (very) lightweight web server and access data using HTTPUrlConnection. This is a wrapper for a socket with HTTP protocol management already implemented. Beware, this is for Java; there is no "standard framework equivalent" for C/C++, I honestly have no idea about objective C.

Please, be also aware of the following:

  • If client and servers has different architectures binary data exchange may get painful, better define your protocol as a sequence of strings (like SMTP) and encode/decode binaries using base64 or some other method you may want to implement
  • In order to link the two sockets client has to know the server IP address; if you are running DHCP on your WIFi network then you also need to implement a discovery phase for your service

As a last side note: "client" and "server" are just labels you put on communicating entities depending on who is requesting a service/information (client) and who is providing it (server). Communication is in reality symmetrical and you can use the same structures/functions/code on both endpoints.


Post a Comment for "Tablet(iPad/Android)-Server Communication Protocol"