/* NAME: tcpClient0 SYNOPSIS: tcpClient0 DESCRIPTION: The program creates a tcp socket in the inet domain, connects to tcpServer0 running at and waiting at port 10203, sends the message "HI" and exits */ #include "def" main(argc, argv ) int argc; char *argv[]; { int sd; struct sockaddr_in server; struct hostent *hp, *gethostbyname(); sd = socket (AF_INET,SOCK_STREAM,0); server.sin_family = AF_INET; hp = gethostbyname(argv[1]); bcopy ( hp->h_addr, &(server.sin_addr.s_addr), hp->h_length); server.sin_port = htons(10203); if (connect(sd, (SA *) &server, sizeof(server))<0){ perror("connect error"); exit (-1); } for (;;) { send(sd, "HI", 2, 0 ); printf("sent HI\n"); sleep(5); } }