一、结构

struct args {  /* 存储参数的结构 */
    long arg1;
    long arg2; 
};

struct result { /* 存储结果的结构 */
    long sum;
};

二、str_cli函数

void str_cli(FILE *fp, int sockfd) {

    char sendline[MAXLINE];
    struct args args;
    struct result result;

    while(fgets(sendline, MAXLINE, fp) != NULL) {
        if (sscanf(sendline, "%ld%ld", &args.arg1, &args.arg2) != 2) {
            printf("invalid input: %s\n", sendline);
            continue;  
        }     
        writen(sockfd, &args, strlen(args));

        if (read(sockfd, recvline, MAXLINE) == 0) {
            return;
        }
        printf("%ld\n", result.sum);
    }
}

三、str_echo函数

void str_echo(int sockfd) {
    ssize_t n;
    struct args args;
    struct result result;

    for ( ; ; ) {
        if ( (n = read(sockfd, &args, sizeof(args)) == 0) {
        return;        
    }
    result.sum = args.arg1 + args.arg2;
    writen(sockfd, &result, sizeof(result));
    }
}

 四、在客户与服务器之间传递二进制结构有什么问题!!!