1. 心跳包
可不可以在Client设一个定时器,每隔一段时间发一条消息给服务器,看能不能收到服务器的响应。
心跳包就是定时发包,没回应就判断断开。
2.api返回值测试:
使用getsockopt测试:
int getsockopt(int socket, int level, int option_name,
void *restrict option_value, socklen_t *restrict option_len);
RETURN VALUE
Upon successful completion, getsockopt() shall return 0; otherwise, -1 shall be returned and errno set to indicate the error.
ERRORS
The getsockopt() function shall fail if:
EBADF The socket argument is not a valid file descriptor.
EINVAL The specified option is invalid at the specified socket level.
ENOPROTOOPT
The option is not supported by the protocol.
ENOTSOCK
The socket argument does not refer to a socket.
The getsockopt() function may fail if:
EACCES The calling process does not have the appropriate