| | |
| | | |
| | | void * client; |
| | | |
| | | void *proxy_server_handler(void *sockt) { |
| | | pthread_detach(pthread_self()); |
| | | |
| | | char action[512]; |
| | | while ( true) { |
| | | printf("Input action: Close?\n"); |
| | | if(scanf("%s",action) < 1) { |
| | | printf("Invalide action\n"); |
| | | continue; |
| | | } |
| | | |
| | | if(strcmp(action, "close") == 0) { |
| | | net_mod_server_socket_close(sockt); |
| | | break; |
| | | } else { |
| | | printf("Invalide action\n"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void start_net_proxy(int port) { |
| | | pthread_t tid; |
| | | printf("Start net proxy\n"); |
| | | void *serverSocket = net_mod_server_socket_open(port); |
| | | |
| | | // 创建一个线程,可以关闭server |
| | | pthread_create(&tid, NULL, proxy_server_handler, serverSocket); |
| | | if(net_mod_server_socket_start(serverSocket) != 0) { |
| | | err_exit(errno, "net_mod_server_socket_start"); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 打印接受到的订阅消息 |
| | | void *print_sub_msg(void *sockt) { |
| | | pthread_detach(pthread_self()); |
| | | void *recvbuf; |
| | |
| | | } |
| | | |
| | | |
| | | void *bus_handler(void *sockt) { |
| | | pthread_detach(pthread_self()); |
| | | |
| | | char action[512]; |
| | | while ( true) { |
| | | printf("Input action: Close?\n"); |
| | | if(scanf("%s",action) < 1) { |
| | | printf("Invalide action\n"); |
| | | continue; |
| | | } |
| | | |
| | | if(strcmp(action, "close") == 0) { |
| | | bus_server_socket_wrapper_close(sockt); |
| | | break; |
| | | } else { |
| | | printf("Invalide action\n"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | void start_bus_server() { |
| | | printf("Start bus server\n"); |
| | | void * server_socket = bus_server_socket_wrapper_open(); |
| | | pthread_t tid; |
| | | // 创建一个线程,可以关闭bus |
| | | // pthread_create(&tid, NULL, bus_handler, server_socket); |
| | | if(bus_server_socket_wrapper_start_bus(server_socket) != 0) { |
| | | printf("start bus failed\n"); |
| | | exit(1); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 交互式客户端 |
| | | void start_net_client(char *sendlist, char*publist ){ |
| | | client = net_mod_socket_open(); |
| | | char content[MAXLINE]; |
| | |
| | | net_mod_recv_msg_t *recv_arr; |
| | | |
| | | pthread_t tid; |
| | | // 创建一个线程接受订阅消息 |
| | | pthread_create(&tid, NULL, print_sub_msg, client); |
| | | |
| | | //192.168.5.10:5000:11, 192.168.5.22:5000:11, 192.168.5.104:5000:11 |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | void *_run_sendandrecv_(void *arg) { |
| | | Targ *targ = (Targ *)arg; |
| | |
| | | |
| | | // port = atoi(argv[2]); |
| | | |
| | | if(opt.fun == NULL) { |
| | | usage(argv[0]); |
| | | exit(1); |
| | | } |
| | | |
| | | if (strcmp("start_net_proxy", opt.fun) == 0 ) { |
| | | if(opt.port == 0) { |
| | |
| | | |
| | | } |
| | | else if (strcmp("start_bus_server", opt.fun) == 0) { |
| | | if(opt.key == 0) { |
| | | usage(argv[0]); |
| | | exit(1); |
| | | } |
| | | |
| | | start_bus_server(); |
| | | } |
| | | else if (strcmp("start_reply", opt.fun) == 0) { |
| | |
| | | |
| | | } |
| | | |
| | | printf("==========end========\n"); |
| | | shm_mm_wrapper_destroy(); |
| | | |
| | | } |
| | | |
| | | |