/* ?????????????????????????????????????? */
bzero(&s_add??sizeof(struct sockaddr_in));
s_add.sin_family=AF_INET;
s_add.sin_addr.s_addr=htonl(INADDR_ANY); /* ??????????0???????? */
s_add.sin_port=htons(portnum);
/* ???bind???а???? */
if(-1 == bind(sfp??(struct sockaddr *)(&s_add)?? sizeof(struct sockaddr)))
{
printf("bind fail ! ");
return -1;
}
printf("bind ok ! ");
/* ?????????????? */
if(-1 == listen(sfp??5))
{
printf("listen fail ! ");
return -1;
}
printf("listen ok ");
while(1)
{
sin_size = sizeof(struct sockaddr_in);
/* accept???????ú???????????????????????????????????????????п??????????????????????????
??????????????????п???????????????????????????Σ????????????????????????
???accept????????????????????????????????
*/
nfp = accept(sfp?? (struct sockaddr *)(&c_add)?? &sin_size);
if(-1 == nfp)
{
printf("accept fail ! ");
return -1;
}
printf("accept ok! Server start get connect from %#x : %#x "??ntohl(c_add.sin_addr.s_addr)??ntohs(c_add.sin_port));
/* ???????write???????????????????????????????????? */
if(-1 == write(nfp??"hello??welcome to my server "??32))
{
printf("write fail! ");
return -1;
}
printf("write ok! ");
close(nfp);
}
close(sfp);
return 0;
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????