Ai
1 Star 0 Fork 0

梁辰鱼/code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
client1-3.c 819 Bytes
一键复制 编辑 原始数据 按行查看 历史
梁辰鱼 提交于 2022-11-30 19:45 +08:00 . 实验4-1socket
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<netinet/in.h>
//20201311
int main()
{
int sockfd = socket(PF_INET,SOCK_STREAM,0);
assert(-1!=sockfd);
struct sockaddr_in ser,cli;
memset(&ser,0,sizeof(ser));
ser.sin_family=AF_INET;
ser.sin_port=htons(6000);
ser.sin_addr.s_addr=inet_addr("127.0.0.1");
int res=connect(sockfd,(struct sockaddr*)&ser,sizeof(ser));
assert(res!=-1);
while(1)
{
printf("Please input:");
fflush(stdout);
char buff[128]={0};
fgets(buff,127,stdin);
buff[strlen(buff)-1]=0;
if(strncmp(buff,"end",3)==0)
{
break;
}
send(sockfd,buff,strlen(buff),0);
memset(buff,0,sizeof(buff));
recv(sockfd,buff,127,0);
printf("%s\n",buff);
}
close(sockfd);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liangchenyu777/code.git
git@gitee.com:liangchenyu777/code.git
liangchenyu777
code
code
master

搜索帮助