| | |
| | | dgram_mod_close_socket(socket); |
| | | } |
| | | |
| | | void client2(int port) { |
| | | void *socket = dgram_mod_open_socket(); |
| | | int size; |
| | | void *recvbuf; |
| | | char sendbuf[512]; |
| | | while (true) { |
| | | sprintf(sendbuf, "hello\n" ); |
| | | dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &size); |
| | | printf("reply: %s\n", (char *)recvbuf); |
| | | free(recvbuf); |
| | | } |
| | | dgram_mod_close_socket(socket); |
| | | } |
| | | |
| | | |
| | | |
| | | void *runclient(void *arg) { |
| | |
| | | port = atoi(argv[2]); |
| | | |
| | | if (strcmp("server", argv[1]) == 0) { |
| | | int temp = shm_alloc_key(); |
| | | printf("tmp=%d\n", temp); |
| | | server(temp); |
| | | } |
| | | |
| | | if (strcmp("client", argv[1]) == 0) |
| | | // int temp = shm_alloc_key(); |
| | | // printf("tmp=%d\n", temp); |
| | | server(port); |
| | | } else if (strcmp("mclient", argv[1]) == 0) { |
| | | startClients(port); |
| | | } else if (strcmp("client", argv[1]) == 0) { |
| | | client(port); |
| | | } else { |
| | | printf("input invalidate arguments\n"); |
| | | } |
| | | |
| | | |
| | | return 0; |