gpt4 book ai didi

c程序与客户端交互

转载 作者:太空宇宙 更新时间:2023-11-04 06:01:26 24 4
gpt4 key购买 nike

<分区>

这是一个c程序(与客户端交互的服务器)我很确定我没有做错什么

我在编译时遇到错误 enter image description here

   int main(int argc, char **argv) 
{
int sock, fd;
socklen_t client_len;
struct sockaddr_in server, client;

if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("Socket failed");
exit(1);
}

server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons (SERVER_PORT);

if (bind ( sock, (struct sockaddr *) &server, sizeof server) == -1);
{
perror("bind failed");
exit(2);
}

listen (sock,1);

while (1)
{
client_len = sizeof (client);
if((fd = accept ( sock, (struct structaddr *) &client, &client_len)) < 0)
{
perror("accepting connection");
exit(3);
}
fprintf(stderr, "\nOpen. \n");
(send (fd, "\nWelcome!\n", 50, 0);
check_stats(fd, fd);
}

close(fd);
fprintf(stderr, "\nClose\n");
exit(0);
}

我附上了屏幕截图,这似乎是个小问题,但我不知道是什么!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com