• 4785阅读
  • 1回复

QUdpSocket 代理设置的问题 [复制链接]

上一主题 下一主题
离线sinboo
 
只看楼主 正序阅读 楼主  发表于: 2009-03-25
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
请教高手:我用一个QUdpSocket发送数据,但死活不能通过代理服务器。

代码大致如下:

  QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::Socks5Proxy);
    proxy.setHostName("192.168.0.200");
    proxy.setPort(1080);
    //proxy.setUser("");
    //proxy.setPassword("");//我的代理服务器不需要用户认证
    QNetworkProxy::setApplicationProxy(proxy);

    QUdpSocket* socket = new QUdpSocket(this);

    socket->bind(QHostAddress::Any,this->ListenPort);
   connect(socket,SIGNAL(readyRead()),this,SLOT(ShowMsg()));


    QByteArray msg("hello");

    if(socket->writeDatagram(msg,this->ServerIP,this->ServerPort)==-1)
    {
         QMessageBox::information(this,"error",QString::number(socket->error()));
    }
    
[ 此帖被sinboo在2009-03-30 11:56重新编辑 ]
离线sinboo
只看该作者 1楼 发表于: 2009-03-25
There are several things to remember when using SOCKS5 with QUdpSocket and QTcpServer:

With QUdpSocket, a call to bind() may fail with a timeout error. If a port number other than 0 is passed to bind(), it is not guaranteed that it is the specified port that will be used. Use localPort() and localAddress() to get the actual address and port number in use. Because proxied UDP goes through two UDP connections, it is more likely that packets will be dropped.

With QTcpServer a call to listen() may fail with a timeout error. If a port number other than 0 is passed to listen(), then it is not guaranteed that it is the specified port that will be used. Use serverPort() and serverAddress() to get the actual address and port used to listen for connections. SOCKS5 only supports one accepted connection per call to listen(), and each call is likely to result in a different serverPort() being used.


看不明白写的是啥意思。。。哪位大侠翻译一下?
快速回复
限100 字节
 
上一个 下一个