/* * SWE 545 - Distributed Systems Programming * Homework 2: Client-server programming skills * * ___Your name___ * File name: simple-client.c (Modify this line when you rename the file) * Last modified: ___date___ */ #include #include #include #include #include #include int main() { int clientfd; short int port_no = 2000; char msg[1000]; struct sockaddr_in servaddr; char *server_ip_address = "127.0.0.1"; printf("Client will connect to the server at IP %s, port #%d\n", server_ip_address, port_no); // Create client socket. clientfd = socket(AF_INET, SOCK_STREAM, 0); printf("Client socket created\n"); // Connect to the server client servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port_no); inet_pton(AF_INET, server_ip_address, &servaddr.sin_addr); connect(clientfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); printf("Client socket connected\n"); // Read one line of message from the input and send it to the server. printf("Enter the message to be sent to the server: "); scanf("%s", &msg); send(clientfd, msg, strlen(msg)+1, 0); close(clientfd); printf("Client sent the message and disconnected. \n"); return 0; }