代码拉取完成,页面将自动刷新
#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);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。