1 Star 1 Fork 0

keeYuc/linuxCodeTest

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cliet.cpp 774 Bytes
一键复制 编辑 原始数据 按行查看 历史
keeYuc 提交于 2020-10-22 21:31 +08:00 . asda
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <iostream>
int main()
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(8888);
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr.s_addr);
connect(fd, (sockaddr *)&addr, sizeof(addr));
char buff[64];
int a;
while (1)
{
memset(buff, 0, 64);
std::cin >> buff;
a = write(fd, buff, strlen(buff));
if (a <= 0)
{
close(fd);
break;
}
memset(buff, 0, 64);
read(fd, buff, 64);
printf("%s\n", buff);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/keeyc/linuxCodeTest.git
git@gitee.com:keeyc/linuxCodeTest.git
keeyc
linuxCodeTest
linuxCodeTest
master

搜索帮助