TCP回射程序
回射程序步骤
- 客户端从标准输入读入一行文本,并发给服务器
- 服务器从网络输入读入这行文本,并且回射给客户
- 客户从网络输入读入这行回射文本,并且显示在标准输出上。
回射流程
TCP 回射服务器
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <strings.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <errno.h>
// 服务器从网络读入和返回
void str_echo(int sockfd) {
ssize_t n;