
40hp= gethostbyname(argv[1]);
41if (hp==0) {
42fprintf(stderr, “%s: Unknown host\n”, argv[1]);
43exit(2);
44}
45memcpy( (char *)&server.sin_addr, (char
46server.sin_port= htons(atoi(argv[2]));
47
48/* Use the connect() socket call to initiate a TCP connection with
49the remote machine. */
50printf(“Connecting...\n”);
51if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0 ) {
52perror(“Connecting stream socket”);
53exit(1);
54}
55printf(“Connected.\n”);
56
57/* Construct message, including Serial Adapter header bytes */
58buf[0]= DATA1;
59buf[3]= 0xf0;
60dataLength= strlen(DATA);
61memcpy(&buf[1], &(htons(dataLength)), sizeof(short));
62strcpy(&buf[4], DATA);
63printf(“%s\n”, &buf[4]);
64
65/* Send message */
66if(write (sock, buf, dataLength+4) < 0)
67perror(“Sending stream message”);
69/* Send $QUIT string to the serial adapter to tell it to close its
70side of the TCP connection. */
71dataLength= 5;
72memcpy(&buf[1], &(htons(dataLength)), sizeof(short));
73memcpy(&buf[4], “$QUIT”, 5);
74if(write (sock, buf, dataLength+4) < 0)
75perror(“Sending $QUIT message”);
77close(sock);
78exit(0);
80}
95