Skip to content

Instantly share code, notes, and snippets.

@brunofrank
Last active April 12, 2018 15:20
Show Gist options
  • Save brunofrank/3035b8289236c6e294c925e506461c1c to your computer and use it in GitHub Desktop.
Save brunofrank/3035b8289236c6e294c925e506461c1c to your computer and use it in GitHub Desktop.
C
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__ );
}
memset(pucData, 0, 128);
while(( nResult = tcp_recv_from_server( nHandle, pucData, 128, __3_SECONDS__)) > 0 ) {
int sizePucData = strlen(pucData);
int sizeOfPucDaTA = sizeof(pucData);
strncat(dataResult, pucData, strlen(pucData));
memset(pucData, 0, 128);
nTotalReceived += nResult;
}
// Disconnect and release the allocated handle.
tcp_disconnect_from_server( nHandle );
} else {
return -1;
}
return nTotalReceived;
}
@maldini15
Copy link

strncat(dataResult, pucData, strlen(pucData)); if the pucData is full of chars (128) the strlen function cant find the end of the string properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment