日期:2014-05-16 浏览次数:20734 次
int main() { int sockfd, connfd; struct sockaddr_in servaddr; socklen_t len; struct linger linger; if (bind(sockfd, (struct sockaddr*)&servaddr, sizeof servaddr) < 0) err_sys("bind error"); if (listen(sockfd, LISTENQ) < 0) err_sys("listen error"); linger.l_onoff = 1; linger.l_linger = 0; if (setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &linger, len) < 0) err_sys("error setlinger\n"); connfd = accept(sockfd, (struct sockaddr*)&servaddr, &len); close(connfd); close(sockfd); return 0; }