void *interpretWrapper(void* arg) {
char* res = (char*) arg;
cout << res[0] << endl;
}
void *recvConn(void * data) {
char buffer[1024];
int buffer_len = 1024;
while(true) {
memset(buffer, 0, buffer_len);
if((bytecount = recv(*csock, buffer, buffer_len, 0)) == -1) {
printf("yalehwyyy\n");
fprintf(stderr, "Error receiving data %d\n", errno);
printf("%d", csock);
break;
}else if (bytecount == 0) {
fprintf(stderr, "Socket Closed ! Robotino needs to reconnect !!\n");
break;
}
pthread_t thread_id = 0;
pthread_create(&thread_id, NULL, interpretWrapper, &buffer);
pthread_detach(thread_id);
printf("Received bytes %d\nReceived string \"%s\"\n", bytecount, buffer);
}
}
In the above code, whenever I receive a string, which is placed into buffer, I print the string in recvConn and the result is in fact the sent string. However, once the string is passed to interpretWrapper, all I get when I print res[0] is an empty char, whereas the expected output would be the first char of the sent string. I also tried using strings, and also got an empty string.
Moreover, I tried sending an integer, whereas printing the integer inside interpretWrapper produced the passed integer correctly. I have been trying to figure it out for two days now, what seems to be the problem?