这可是最经典的代码哟!:) SOCKET s; fd_set fdread; int ret;// Create a socket, and accept a connection// Manage I/O on the socket while(TRUE) { // Always clear the read set before calling // select() FD_ZERO(&fdread); // Add socket s to the read set FD_SET(s, &fdread); if ((ret = select(0, &fdread, NULL, NULL, NULL)) == SOCKET_ERROR) { // Error condition } if (ret > 0) { // For this simple case, select() should return // the value 1. An application dealing with // more than one socket could get a value // greater than 1. At this point, your // application should check to see whether the // socket is part of a set. if (FD_ISSET(s, &fdread)) { // A read event has occurred on socket s } } }
SOCKET s;
fd_set fdread;
int ret;// Create a socket, and accept a connection// Manage I/O on the socket
while(TRUE)
{
// Always clear the read set before calling
// select()
FD_ZERO(&fdread); // Add socket s to the read set
FD_SET(s, &fdread); if ((ret = select(0, &fdread, NULL, NULL, NULL))
== SOCKET_ERROR)
{
// Error condition
} if (ret > 0)
{
// For this simple case, select() should return
// the value 1. An application dealing with
// more than one socket could get a value
// greater than 1. At this point, your
// application should check to see whether the
// socket is part of a set. if (FD_ISSET(s, &fdread))
{
// A read event has occurred on socket s
}
}
}
FD_ZERO(&fdRecv);
FD_SET(SocketConnect,&fdRecv);
timeval tm;
tm.tv_sec=30;
tm.tv_usec=0; int rc=select(0,&fdRecv,NULL, NULL,&tm);
if(rc==0)
{
return;
} rc=recv(SocketConnect,pBuf,nBytes,0);