6.2. 简易的 Stream Client
Client 这家伙比 server 简单多了,client 所需 要做的就是:连线到你在命令行所指定的主机 3490 port,接着,client 会收到 server 送回的字符串。
Client 的代码 [21]:
[21] http://beej.us/guide/bgnet/examples/client.c
/*
/*
** client.c -- 一个 stream socket client 的 demo
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define PORT "3490" // Client 所要连接的 port
#define MAXDATASIZE 100 // 我们一次可以收到的最大字节数量(number of bytes)