#include #include #include #include #include #include #include #include #include int main(int argc, char* argv[]) { const char *server_name = "127.0.0.1"; int sockfd, connfd; struct sockaddr_in servaddr, cli; sockfd = socket(AF_INET, SOCK_STREAM, 0); servaddr.sin_family = AF_INET; inet_pton(AF_INET, server_name, &servaddr.sin_addr); int port = atoi(argv[1]); servaddr.sin_port = htons(port); if((connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) == 0) { printf("Connected to server!\n"); fflush(stdout); } else { printf("Invalid or busy server address\n"); fflush(stdout); exit(0); }; int cont = 0; char *buf = malloc(1024); printf("Client input: "); fgets(buf, 100, stdin); while(strcmp(buf, "quit\n") != 0) { send(sockfd, buf, 100, 0); if ((cont = recv(sockfd, buf, 100, 0)) > 0) { printf("Server response: %s\n", buf);; fflush(stdout); } printf("Client input: "); fgets(buf, 100, stdin); }; close(sockfd); }