#include #include #include #include #include #include #include #include #define DEST_IP "127.0.0.1" //#define DEST_IP "216.109.112.135" #define DEST_PORT 3490 //#define DEST_PORT 80 main() { int sockfd; struct sockaddr_in dest_addr; /* will hold the destination addr */ sockfd = socket(AF_INET, SOCK_STREAM, 0); /* do some error checking! */ dest_addr.sin_family = AF_INET; /* host byte order */ dest_addr.sin_port = htons(DEST_PORT); /* short, network byte order */ dest_addr.sin_addr.s_addr = inet_addr(DEST_IP); memset(&(dest_addr.sin_zero), 8, 0); /* zero the rest of the struct */ /* don't forget to error check the connect()! */ connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)); char buf[30000]; while (true) { read(sockfd, buf, sizeof(buf)); printf("%s", buf); char mybuf[200]; printf("Enter a string: "); fgets(mybuf, sizeof(mybuf), stdin); printf("Sending this message: %s\n", mybuf); write(sockfd, mybuf, strlen(mybuf) + 1); if (0 == strncasecmp(mybuf, "quit", 4)) { break; } } }