#include /* obligatory includes */ #include #include #include #include #include #include #include #include #include "sockets.h" #define PORT_NUM 50000 int main(int argc, char **argv) { char buf[100]; int socket = -1; int x, y; char *hostname; int portnum; if (argc != 3) { printf("%s \n", argv[0]); return -1; } hostname = argv[1]; sscanf(argv[2], "%d", &portnum); if ((socket = call_socket(hostname, portnum)) < 0){ perror("call_socket"); exit (1); } strcpy(buf, "QUERY"); write_data(socket, buf, strlen(buf)+1); printf("client sent \"%s\" to socket %d\n", buf, socket); read_string(socket, buf); sscanf(buf, "%d %d", &x, &y); printf("client received \"%s\" from socket %d\n", buf, socket); printf("x = %d, y = %d\n", x, y); /* when done with all communication */ close(socket); }