#include
#include //定义了sockaddr_in结构体
#include
#include
int main()
{
int listen_fd;
int optvalue;
struct sockaddr_in server;
server.sin_family=AF_INET;
server.sin_port=htons(8080);
server.sin_addr.s_addr=htonl(INADDR_ANY);
if((listen_fd=socket(AF_INET,SOCK_STREAM,0))<0)
{
printf("call socket error\n");
exit(1);
}
setsockopt(listen_fd,SOL_SOCKET,SO_REUSEADDR,&optvalue,sizeof(int));
if(bind(listen_fd,(struct sockaddr*)&server,sizeof(server))<0)
{
printf("bind error\n");
exit(1);
}
if(listen(listen_fd,5)<0)
{
printf("listen error\n");
exit(1);
}
accept(listen_fd,NULL,NULL);
}
阅读(1672) | 评论(0) | 转发(1) |