- 论坛徽章:
- 0
|
stevens的UNIX网络编程上例程联不上,大家帮忙看一下
服务器端程序:
ser.c
#include "unp.h"
int
main(int argc,char** argv)
{
int listenfd,connfd;
struct sockaddr_in servaddr;
char buff[MAXLINE];
time_t ticks;
listenfd=socket(AF_INET,SOCK_STREAM,0);
printf("socket connection over\n" ;
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
bind(listenfd,(SA *)&servaddr,sizeof(servaddr));
printf("bind over\n" ;
listen(listenfd,LISTENQ);
printf("listen over\n" ;
for(;
{
printf("accepting...\n" ;
connfd = accept(listenfd,(SA *)NULL,NULL);
printf("accepted!!!\n" ;
ticks=time(NULL);
snprintf(buff,sizeof(buff),"%.24s\r\n",ctime(&ticks));
write(connfd,buff,strlen(buff));
printf("write over\n" ;
close(connfd);
}
} |
|