int main(int argc, char *argv[]) { int socket_fd, value; char server_ip[32]; int i; char path[128]; FILE *file; struct sockaddr_in addr; struct thread_struct *job; pthread_barrier_t bar; if (argc != 2) { printf("Usage: %s <IP of Server>", argv[0]); exit(EXIT_FAILURE); } strncpy(server_ip, argv[1], 15); printf("\n - Welcome in the XYZ file tranfer. -\n"); printf("\nChoose what you want to do:\n\n"); printf("\t[ get <fileName> ]: you can download a file from the server.\n"); printf("\t[ put <filePath> ]: you cand add a file from your PC to the server.\n"); printf("\t[ list ]: see what's on the server.\n\n"); pthread_barrier_init(&bar, NULL, 2); sprintf(path,"/home/dorel/Scrivania/tempi_80MB_0p_50msg_30fin"); file = fopen(path, "w+"); for(i = 0; i < 5; i++) { job = alloc(sizeof(struct thread_struct)); addr = init_socket_client(&socket_fd, server_ip); job->node = Connect(socket_fd, addr); job->bar = &bar; job->file = file; value = pthread_create(&(job->tid), NULL, manage_input, job); if (value != 0) { perror("Error in creating a new thread."); exit(EXIT_FAILURE); } pthread_barrier_wait(&bar); printf("\nInsert another request.\n"); usleep(5000000); } fclose(file); return EXIT_SUCCESS; }
//此线程用于接收来自汇聚节点的ip void *start_server2() { int sockfd; char ip[20]; int i = 0; init_ipnode(); sockfd = init_socket_client("/root/onesafe/code/jun/conf8"); if(sockfd < 0) { printf("init_socket_client error\n"); } while(1) { memset(ip, 0, sizeof(ip)); read(sockfd, ip, 20); printf("recv ip is %s\n", ip); pthread_mutex_lock(&ipLock); for(i=0; i<ipnodeLen; i++) { if(!strcmp(ip, ipnode[i].ip)) { if((ipnode[i].flag == 0)) { strcpy(ipnode[i].ip, ip); ipnode[i].shou_socket = sockfd; ipnode[i].flag = 1; } } } pthread_mutex_unlock(&ipLock); sleep(3); } }
int main(int argc, char *argv[]) { int socket_fd, value; char server_ip[32]; struct sockaddr_in addr; struct thread_struct *job; pthread_barrier_t bar; if (argc != 2){ printf("Usage: %s <IP of Server>", argv[0]); exit(EXIT_FAILURE); } strncpy(server_ip, argv[1], 15); printf("\n - Welcome in the XYZ file tranfer. -\n"); printf("\nChoose what you want to do:\n\n"); printf("\t[ get <fileName> ]: you can download a file from the server.\n"); printf("\t[ put <filePath> ]: you cand add a file from your PC to the server.\n"); printf("\t[ list ]: see what's on the server.\n\n"); pthread_barrier_init(&bar, NULL, 2); while(1){ job = alloc(sizeof(struct thread_struct)); addr = init_socket_client(&socket_fd, server_ip); job->node = Connect(socket_fd, addr); job->bar = &bar; value = pthread_create(&(job->tid), NULL, manage_input, job); if (value != 0){ perror("Error in creating a new thread."); exit(EXIT_FAILURE); } pthread_barrier_wait(&bar); printf("\nInsert another request.\n"); } return EXIT_SUCCESS; }
//此线程用于接收来自汇聚节点的文件 void *start_server1() { int sockfd; sockfd = init_socket_client("/root/onesafe/code/jun/conf9"); if(sockfd < 0) { printf("init_socket_client error\n"); } while(1) { if(recv_file(sockfd) < 0) { printf("send_file error\n"); } sleep(3); } }