empty character constant 这是什么原因
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/30 01:01:07
empty character constant 这是什么原因
empty character constant 这是什么原因
empty character constant 这是什么原因
server.c代码来啦~~~不好意思,晚了些时间:)
/* server.c */
#include
#include
#include
#include
#include
#include
#include
#include
main () {
int sockfd,new_fd;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int sin_size,numbytes;
char buff[100];
if ((sockfd = socket(AF_INET,SOCK_STREAM,0))==-1) {
perror("socket");
exit(1);
}
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(2323);
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
if (bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr))==-1) {
perror("bind");
exit(1);
}
if (listen(sockfd,10)==-1) {
perror("listen");
exit(1);
}
while(1) {
sin_size = sizeof(struct sockaddr_in);
perror("server is running");
if ((new_fd = accept(sockfd,(struct sockaddr *)&their_addr,&sin_size))==-1) {
perror("accept");
exit(1);
}
if (!fork()) {
if ((numbytes = recv(new_fd,buff,strlen(buff),0))==-1 )
perror("recv");
exit(1);
}
printf ("%s",buff);
if (send(new_fd,buff,strlen(buff),0)==-1) {
perror("send");
close(new_fd);
exit(0);
}
close(new_fd);
}
close(sockfd);
}