Setting Socket Timeout?

后端 未结 3 816
北海茫月
北海茫月 2021-01-18 09:13

Using sockets, I am not sure how to set the timeout?

thanks

int sock, connected, bytes_recieved;
char send_data [128] , recv_data[128];       
SOCKAD         


        
3条回答
  •  广开言路
    2021-01-18 09:27

    you can use:

    fd_set fd;
    timeval tv;
    FD_ZERO(&fd);
    FD_SET(sock, &fd);
    tv.tv_sec = time_out(second);
    tv.tv_usec = 0;
    

    to set timeout for sending,receiving data.

提交回复
热议问题