注意:服务器中的ip(192.168.31.122)和端口号port(6666)客户端中必须一致
编译:客户端:gcc tcp_client.c -o client
服务器:gcc tcp_server.c -o server
运行:客户端:./client
服务器:./server 192.168.31.122 6666
客户端:
tcp_client.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#define SIZE 64
int main(int argc, char *argv[])
{
int sockfd = socket(AF_INET, SOCK_STREAM, 0);//创建网络通信接口
if(-1 == sockfd)
{
perror("socket");
return -1;
}
printf("sockfd=%d\n&#