#include #include #include #include #include #include #include #include #include int sw ; void *thread_function1(void * arg) { printf("exc f1 \n"); int sock; struct sockaddr_in addr; char buf[2048]; sock = socket(AF_INET, SOCK_DGRAM, 0); addr.sin_family = AF_INET; addr.sin_port = htons(12345); addr.sin_addr.s_addr = INADDR_ANY; bind(sock, (struct sockaddr *)&addr, sizeof(addr)); while(1){ memset(buf, 0, sizeof(buf)); recv(sock, buf, sizeof(buf), 0); printf("%s\n", buf); if(buf[0]=='q'){ sw =0; break; } } close(sock); return NULL; } int main(void) { pthread_t thread1; pthread_create( &thread1, NULL, thread_function1,NULL); sw=1; while( sw ) { printf(".\n"); sleep(1); } return 0; }