Gateway::sendUdpAndRecv PHP Method

sendUdpAndRecv() protected static method

发送udp数据并返回
protected static sendUdpAndRecv ( integer $address, $data ) : boolean
$address integer
return boolean
    protected static function sendUdpAndRecv($address, $data)
    {
        $buffer = GatewayProtocol::encode($data);
        // 非workerman环境,使用udp发送数据
        $client = stream_socket_client("udp://{$address}", $errno, $errmsg);
        if (strlen($buffer) == stream_socket_sendto($client, $buffer)) {
            // 阻塞读
            stream_set_blocking($client, 1);
            // 1秒超时
            stream_set_timeout($client, 1);
            // 读udp数据
            $data = fread($client, 655350);
            // 返回结果
            return json_decode($data, true);
        } else {
            throw new \Exception("sendUdpAndRecv({$address}, \$bufer) fail ! Can not send UDP data!", 502);
        }
    }