-
-
Save flaviodesousa/b60105ce0c76f09d9b853e91d225da81 to your computer and use it in GitHub Desktop.
C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void getAndPrintGameTable(){ | |
char gamesTable[12800]; | |
memset(gamesTable, 0, 12800); | |
int iRet; | |
GL_Dialog_Message(xGoal, NULL, "Aguarde...", GL_ICON_INFORMATION, GL_BUTTON_NONE, 0); | |
iRet = GetJsonFromServer("GET_GAMES_TABLE", gamesTable); | |
if (iRet >= 0) | |
printGameTable(gamesTable); | |
else | |
GL_Dialog_Message(xGoal, NULL, "Tente novamente!", GL_ICON_ERROR, GL_BUTTON_NONE, 3000); | |
free(gamesTable); | |
} | |
int GetJsonFromServer(char *msg, char *dataResult) { | |
int nHandle = 0; | |
int nResult = 0; | |
int nTotalReceived = 0; | |
unsigned char formatedMsg[64]; | |
unsigned char pucData[128]; | |
char serialNumber[15]; | |
PSQ_Give_Full_Serial_Number(serialNumber); | |
// Connect to IP Test server. | |
nResult = tcp_connect_to_server(__IP_ADDRESS, 8000, __20_SECONDS__ ); | |
if( nResult >= 0 ) { | |
nHandle = nResult; | |
// AUTENTICA NA API | |
memset(formatedMsg, 0, 64); | |
sprintf(formatedMsg, "IM:%s;AK:%s\n", serialNumber, __APP_KEY); | |
while(( nResult = tcp_send_to_server(nHandle, formatedMsg, strlen(formatedMsg), __INFINITE__ )) == ERROR_TIMEOUT ) { | |
ttestall( 0, __100_MSECONDS__ ); | |
} | |
memset(formatedMsg, 0, 64); | |
sprintf(formatedMsg, "%s\n", msg); | |
while(( nResult = tcp_send_to_server(nHandle, formatedMsg, strlen(formatedMsg), __INFINITE__ )) == ERROR_TIMEOUT ) { | |
ttestall( 0, __100_MSECONDS__ ); | |
} | |
void *dest = dataResult; | |
while(( nResult = tcp_recv_from_server( nHandle, dest, 128, __3_SECONDS__)) > 0 ) { | |
dest += nResult; | |
nTotalReceived += nResult; | |
} | |
// Disconnect and release the allocated handle. | |
tcp_disconnect_from_server( nHandle ); | |
} else { | |
return -1; | |
} | |
return nTotalReceived; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment