Files
C-exp-collection/server-exp3/togglec.c

31 lines
657 B
C
Raw Normal View History

2026-06-18 18:13:12 +08:00
#include "common.h"
int main(int argc, char **argv)
{
int client_sock, port;
char *host, buf[MAXLINE];
rio_t rio;
if (argc != 3) {
fprintf(stderr, "usage: %s <host><port>\n", argv[0]);
exit(1);
}
host = argv[1];
port = atoi(argv[2]);
client_sock = open_client_sock(host, port);
if(client_sock==-1) {
fputs("Error to connect the Server\n",stdout);
exit(1);
}
while (fgets(buf, MAXLINE, stdin) != NULL) {
//sleep(1);
send(client_sock, buf, strlen(buf),0);
recv(client_sock, buf, MAXLINE,0);
fputs(buf, stdout);
}
close(client_sock);
exit(0);
}