I am building a professional iOS application where an iPad is a server and several iPhones are clients.
Considering the fact that : - communications operate only on a local network via sockets using TCP. - I want to keep all of them in sync (all devices have a local database) - I want to be able to send commands like NEW, UPDATE, DELETE, etc to keep them in sync - I want be able to send notifications with some data attached (audio file), - I want to define priorities for all of theses commands.
It makes me think that a need to define a protocol, so my question is : Does one already exist ?
Thanks a lot !
You can listen socket messages, server can send simple structs with data url, commands to clients, and after that they can update data for example:
#define MSG_DOWNLOAD 1
typedef struct{
uint8_t cmd;
uint8_t size;
} MSGHEADER
typdef struct{
MSGHEADER header;
char url[255];
} MSGDOWNLOAD;
and in socket if you will get header with cmd = 1, you can send NSURLconnetion with url to your server and download some data and sync it.
- (void)recivedDataFromBuffer:(NSData *)data
{
MSGHEADER *pMsgHdr;
pMsgHdr = (MSGHEADER*)[data bytes];
int headerCMD = pMsgHdr->cmd;
if (headerCMD == MSG_DOWNLOAD)
{
MSGDOWNLOAD download = *(MSGDOWNLOAD *)pMsgHdr;
download.header = *pMsgHdr;
// do sync stuff send url request etc.
}