请帮我实现下,多谢
void CSocketServer::RecMsg(char *RecMsg)
{
while (1)
{
char buffer[1024]="\0";
if (recvfrom(m_Socket,RecMsg,2048,0,(struct sockaddr*)&m_from,&m_fromlen)!=SOCKET_ERROR)
{
return;
void CSocketServer::RecMsg(char *RecMsg)
{
fd_set rset;
struct timeval tv;
FD_ZERO(&rset);
FD_SET(clifd,&rset);
tv.tv_sec = 2;(等待时间间隔秒数,要立即查看端口有没有数据需要读的话可设置为0)
tv.tv_usec = 0;
while(1)
{
if (select(m_Socket + 1,&rset,NULL,NULL,&tv) <= 0)
{
printf("nothing to read!\n");
}
else
{
recvfrom(m_Socket,RecMsg,2048,0,(struct sockaddr*)&m_from,&m_fromlen);
}
}
return;
}