SENA HD132x Series User Manual
Page 45
HD132x Series User Manual
45
{
char bufReceived[BUFSIZE];
int nCountReceived = 0;
int nCommand = 0;
int nShowMenu = 0;
memset(bufReceived,'\0',sizeof(bufReceived));
while(1) {
//---------------------------------------------------------
// receives data from a connected socket(HD1320)
//---------------------------------------------------------
nCountReceived = recv(sockClient,bufReceived,sizeof(bufReceived),0);
if (nCountReceived == 0) { // HelloDevice closed the client socket
printf("Disconnected from client[%d.%d.%d.%d]\n"
,addrClient.sin_addr.S_un.S_un_b.s_b1
,addrClient.sin_addr.S_un.S_un_b.s_b2
,addrClient.sin_addr.S_un.S_un_b.s_b3
,addrClient.sin_addr.S_un.S_un_b.s_b4);
DisplayMenu();
scanf("%d", &nCommand);
return nCommand;
} else if (nCountReceived < 0) {
if (++nShowMenu == SHOWMENU) {
DisplayMenu();
scanf("%d", &nCommand);
return nCommand;
} else {
continue;
}
} else { // received some data
// Send echo to client
if(!SerialSend(bufReceived, nCountReceived)){ // Sending echo error
printf("Fail to send echo to client[%d.%d.%d.%d]\n"
,addrClient.sin_addr.S_un.S_un_b.s_b1
,addrClient.sin_addr.S_un.S_un_b.s_b2
,addrClient.sin_addr.S_un.S_un_b.s_b3
,addrClient.sin_addr.S_un.S_un_b.s_b4);
DisplayMenu();