服务器端#include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include
<stdio.h> #include <arpa/inet.h> int main() { //socket int cliFd =
socket(PF_INET, SOCK_STREAM, 0); if(cliFd < 0) { perror("socket error!");
return -1; } printf("socket ok!\n"); //connect struct sockaddr_in servAddr =
{0}; servAddr.sin_family = PF_INET; servAddr.sin_port = htons(8888);
servAddr.sin_addr.s_addr = inet_addr("192.168.31.100"); int ret =
connect(cliFd, (struct sockaddr *)&servAddr, sizeof(servAddr)); if(ret < 0) {
perror("connect error!"); return -1; } printf("connect ok!\n"); //send char
buf[1024] = {0}; printf("please input:"); scanf("%s", buf); send(cliFd, buf,
sizeof(buf), 0); //close close(cliFd); return 0; }
终端#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include
<arpa/inet.h> #include <unistd.h> int main() { //socket int servFd =
socket(PF_INET, SOCK_STREAM, 0); if(servFd < 0) { perror("socket error!");
return -1; } printf("socket ok!\n"); //bind struct sockaddr_in servAddr = {0};
servAddr.sin_family = PF_INET; servAddr.sin_port = htons(8888);
servAddr.sin_addr.s_addr = inet_addr("192.168.31.100"); int ret = bind(servFd,
(struct sockaddr *)&servAddr, sizeof(servAddr)); if(ret < 0) { perror("bind
error!"); return -1; } printf("bind ok!\n"); //listen ret = listen(servFd, 10);
if(ret < 0) { perror("listen error!"); return -1; } printf("listening.....\n");
//accept int connFd = accept(servFd, NULL, NULL); if(connFd < 0) {
perror("accept error!"); return -1; } printf("accept ok!\n"); //recv char
buf[1024] = {0}; ret = recv(connFd, buf, sizeof(buf), 0); if(ret > 0) {
printf("recv form client: %s\n", buf); } //close close(servFd); close(connFd);
return 0; }

技术
©2019-2020 Toolsou All rights reserved,
(精华2020年6月2日更新) TypeScript函数详解vue 获取el-select选中项的label值Python 读取Excel某一列|转存json(精华2020年6月3日更新) TypeScript中接口详解数字滚动抽奖小程序(精华)2020年8月9日 C#基础知识点 反射Map 判断key对应的value值是否存在-containsKey()python原语--锁Lock指定位置输出字符串(详细解析)在vue+element-ui中,select选项值动态从后台获取,同时将选中值的id传给后台的方法