我有一个类,希望得到一个udp或tcp套接字。
现在,我想检查一下,给了班级什么样的插座。
class NetClientWriter {
public __construct($socket=null) {
// do we have a socket?
if(!is_null($socket)) {
if(!is_resource($socket) ||
strtolower(get_resource_type($socket))!='socket')
throw new InvalidSocketTypeExeption("This is not a resource of type socket.");
}
// socket type
if(socket_get_option($socket, SOL_SOCKET, SO_TYPE)==SOCK_STREAM) {
echo("TCP!!!!!");
}
elseif(socket_get_option($socket, SOL_SOCKET, SO_TYPE)==SOCK_DGRAM) {
echo("UDP!!!!!");
}
else throw new InvalidSocketTypeExeption("Invalid socket type. Just UDP and TCP sockets supported.");
}
}
非常感谢