1 #if defined(__MWERKS__) && defined(macintosh)
3 #elif defined(_Windows)
12 # include <sys/types.h>
23 int argc
= ccommand(&argv
);
25 void main(int argc
, char *argv
[])
28 Sock_port_t portnumber
= 7;
33 char *hostname
= "localhost";
36 case 3: portnumber
= atoi(argv
[2]);
37 case 2: hostname
= argv
[1];
40 fprintf(stderr
, "Usage: %s host port\n", argv
[0]);
44 if (Sock_init() != 0) {
45 fprintf(stderr
, "Sock initialization failed");
49 if ((sockfd
= Sock_connect(portnumber
, hostname
, NULL
)) < 0) {
50 perror("Unable to establish an Internet connection");
53 fprintf(stderr
, "Connection has been made to %s\n", hostname
);
56 for (bytesread
= 0; bytesread
< BLKSIZE
; bytesread
++) {
60 else if (ch
== '\n') {
61 buf
[bytesread
++] = ch
;
67 if (bytesread
<= 0) break;
69 byteswritten
= Sock_write(sockfd
, buf
, bytesread
, NULL
);
70 if (byteswritten
!= bytesread
) {
72 "Error writing %ld bytes, %ld bytes written\n",
73 (long)bytesread
, (long)byteswritten
);
77 bytesread
= Sock_read(sockfd
, buf
, BLKSIZE
, NULL
);
78 for (i
= 0; i
< bytesread
; i
++)
82 Sock_close(sockfd
, NULL
);