hello,
i'm trying to write a UDP client for a basic "chat" service, basically i want the client to receive and print messages sent to it from the server, however still allow the user to enter text and send messages to other "rooms'. i create a thread with pthread_create() and i can receive one message but it seems as though the thread never returns. heres a simplified main()
Code:
int main(int argc, char* argv[])
{
/*
*server setup and client initialisation
*/
pthread_create(&thrid, 0, receiveThread, &server);
while(1) {
if(typeFlag) {
printf("Enter text: ");
fgets(buf, MSG_SIZE, stdin);
//typeFlag = 0;
}
/**
*do a bunch of stuff based on incoming messages
*/
}
pthread_join(thrid, NULL);
close(server.socket);
return 0;
}
and the "listener" thread, basically receives and prints incoming messages
Code:
void* receiveThread(void* arg)
{
char buf[MSG_SIZE];
Server* server = (Server*)arg;
receiveMessage(server, buf);
printf("buf: %s", buf);
return NULL;
}
so basically i want the thread to print the mesage and return and go back to the fgets() so user can input more commands etc, but still "automatically" print any mesage which comes to it. but currently it stops after the printf("buf") and receives no more messages until i press return. so if anyone could give me any pointers how i can acheive what i've (attempted) to describe it would be most appreciated,
cheers,