Src
|
|
Server:
...
49
50 void work(int fd)
51 {
52 write(fd, "a", strlen("a" ) );
53 write(fd, "bb", strlen("bb" ) );
54 write(fd, "ccc", strlen("ccc" ) );
55 write(fd, "dddd", strlen("dddd" ) );
56 write(fd, "eeeee", strlen("eeeee" ) );
57 write(fd, "ffffff", strlen("ffffff" ) );
58 write(fd, "ggggggg", strlen("ggggggg" ) );
59 write(fd, "", 0 );
60
61 }
...
Client:
...
50 int main(int argc, char **argv)
51 {
52 int fd, n;
53 char data[10];
54
55 if (argc != 2 )
56 fprintf(stderr, "%s: %s host\n",
57 argv[0], argv[0] ),
58 exit(1);
59
60 fd = hp_open_tcp_client_con( argv[1], PORT );
61 while ( (n = read(fd, data, sizeof(data) - 1 )) > 0) {
62 data[n] = '\0';
63 printf("%d: --%s-- (n = %d)\n", (int)getpid(), data, n );
64 }
65
66 if ( n < 0 )
67 perror("read error"), exit(1);
68
69 close(fd);
70 exit(0);
71 }
...
Result:
# server first % 9_s_size Offering Port: 9999 Waiting (0 clients called) ... Waiting (1 clients called) ...
# client send % 9_c_size ilon 29862: --abb-- (n = 3) 29862: --cccddddee-- (n = 9) 29862: --eeeffffff-- (n = 9) 29862: --ggggggg-- (n = 7)
Src
|
|
Last modified: 08/May/98 (11:53)