不要建议我用indy9或indy10,条件所限,我只能使用indy8

解决方案 »

  1.   

    你所谓的代理服务器是什么?socks吗?都不说清楚,呵,
    如果是socks5的话,可以找一下相关的协议看一下就可以了。
      

  2.   

    局域网的PC通过代理服务器上网,现在我想在这些机器上用udp的方式向外面发送数据,怎样做?
      

  3.   

    >>局域网的PC通过代理服务器上网
    代理服务器是http代理?sock5代理?如果是http代理,那是没有办法的~~~~如果是sock5代理又可以不用管~~~~~~`郁闷~~~~~~~~`
      

  4.   

    如果是socket5代理,不用做任何设置就可以向外发UDP包吗?
      

  5.   

    >>如果是socket5代理,不用做任何设置就可以向外发UDP包吗?
    不是的~~~~~`^_^
    帖一片C++的~~~~~~
    用socks5进行udp发送数据的过程:1, 和代理建立tcp联接,(你已经完成)
    2,向代理发送版本的请求信息,
       我的实现:
    void CCommunicator::SendVer ()
    {
            int datasize = 6;
            char tempbuf[6];
        
        tempbuf[0] = 5;
        tempbuf[1] = 4;//标示后面所根的字接数
        tempbuf[2] = 0;
        tempbuf[3] = 1;
        tempbuf[4] = 2;
        tempbuf[5] = 3;
        int senddatalen;
        senddatalen = send(m_sock, (char *)tempbuf, 6, 0 );
    }
    如果失败,断开建立的tcp联接,
    如果成功,如果需要用户验证则进行步骤3,否则进行4,
    3,如果需要用户验证,则
    类似:
       BOOL CCommunicator::SendUserTest()
    {
        int usernamelen=0;
        int userpasslen=0;
        usernamelen = m_strTestUserName.GetLength();
        userpasslen = m_strTestUserPass.GetLength();
        char tempbuf[100];
        
        tempbuf[0] = 5;
        tempbuf[1] = usernamelen;//标示后面所根的字接数
        strcpy(&tempbuf[2],m_strTestUserName);
        
        tempbuf[2+usernamelen] = userpasslen;
        strcpy((char *)&tempbuf [3+usernamelen] ,m_strTestUserPass);
        
        int senddatalen;
        int len;
        len = usernamelen +userpasslen + 3;
        senddatalen = send(m_sock, (char *)tempbuf, len, 0 );
    }
      如果失败,断开建立的tcp联接,
      如果用户返回成功,步骤4
    4,发送请求的协议
    类似:
    void CCommunicator::SendRequestUDP ()
    {   int const datasize = 10;
       BYTE tempbuf[datasize];
       tempbuf[0] = 5;
       tempbuf[1] = 3;//标示UDP连接
       tempbuf[2] = 0;
       tempbuf[3] = 1;
       tempbuf[4] = 0;
       tempbuf[5] = 0;
       tempbuf[6] = 0;
       tempbuf[7] = 0;
       *((SHORT*)(&(tempbuf[8]))) = m_uBindUDPPort;
       //UDP在客户端绑定的端口,就是你本地机器的做udp数据传送的端口,调用
       // socket函数后,再调用bind()来邦定一个端口。
       char temp;
       temp = tempbuf[8] ;
       tempbuf[8] = tempbuf[9];
       tempbuf[9] = temp;   int senddatalen = send(m_sock, (char *)tempbuf, datasize, 0 );
     }
     如果失败,断开建立的tcp联接,
     如果返回成功,验证完毕!步骤5
    5,真正的数据传送,用代理传送的时候,数据包的前面加上10个字节
    类似:
     void CCommunicator::CopyDataHead(BYTE * ptempbuf)
    {
        struct in_addr addr;
        addr.s_addr = inet_addr(“202.220.33.333”);//这个ip是服务器端的ip
                
        ptempbuf[0] = 0;
        ptempbuf[1] = 0;
        ptempbuf[2] = 0;
        ptempbuf[3] = 1;
        ptempbuf[4] = (char)addr.S_un.S_un_b.s_b1;;
        ptempbuf[5] = (char)addr.S_un.S_un_b.s_b2;
        ptempbuf[6] = (char)addr.S_un.S_un_b.s_b3;
        ptempbuf[7] = (char)addr.S_un.S_un_b.s_b4;
       
        *((SHORT*)(&(ptempbuf[8]))) = m_uServerUDPPort;//服务器的端口,就是你最终要发到那个服务器的端口,也就是你的qq服务器。
        char temp;
        temp = ptempbuf[8] ;
        ptempbuf[8] = ptempbuf[9];
        ptempbuf[9] = temp;
    }
    真正发送的时候类似:
    int CCommunicator::SendBufferUDP(LPBYTE lpBuf,int nLen)
    {
        BYTE tempbuf[1000];
        int iHeadData = 0;
        struct sockaddr_in her;
        her.sin_family = AF_INET;
        her.sin_addr.s_addr = inet_addr(m_szProxyAddr);//代理服务器
             her.sin_port = htons(m_uSocksPort);//发送请求的时候返回的代理服务器端的端口,记住,这是最重要的。
             CopyDataHead(tempbuf);
        iHeadData = 10;
        nLen=nLen + 10;
        int addr_len;
        addr_len = sizeof(struct sockaddr);
      
        CopyMemory((char *)&tempbuf[iHeadData],lpBuf,nLen);
        int returndatalen = sendto(m_socket,(char *)tempbuf,nLen,0,(struct sockaddr *)&her,addr_len);
        
    }
    希望对你有帮助!
      

  6.   

    //捡复杂点的翻译为delphi
    3,如果需要用户验证,则类似:
    procedure SendUserTest();
    var
      usernamelen : integer;
      userpasslen : Integer;
      len : integer;
      tempbuf : Array [0..127] of Byte;
    begin
      usernamelen := length(editUserName.text);
      userpasslen := length(editUserPass.text);
        
      tempbuf[0] := 5;
      tempbuf[1] := usernamelen;//标示后面所根的字接数
      Move( editUserName.text[1], tempbuf[2], UserNamelen );
        
      tempbuf[2+usernamelen] := userpasslen;
      move( editUserPass.text[1], tempbuf [3+usernamelen] ,userpasslen );
        
      len := usernamelen +userpasslen + 3;
      send( m_sock, tempbuf[0], len, 0 );
    end;
      

  7.   

    4,发送请求的协议
    类似:
    procedure SendRequestUDP ();
    const datasize = 10;
    var
      tempbuf: array[0..datasize-1] of byte;
      p : PWord;
      b : byte;
    begin
       tempbuf[0] := 5;
       tempbuf[1] := 3;//标示UDP连接
       tempbuf[2] := 0;
       tempbuf[3] := 1;
       tempbuf[4] := 0;
       tempbuf[5] := 0;
       tempbuf[6] := 0;
       tempbuf[7] := 0;
       p := @tempbuf[8];
       p^ := LocalBindUDPPort;//UDP在客户端绑定的端口,
                             //就是你本地机器的做udp数据传送的端口,调用
                            // socket函数后,再调用bind()来邦定一个端口。
       b := tempbuf[8] ;//把主机顺序转化为网络顺序
       tempbuf[8] := tempbuf[9];
       tempbuf[9] := b;   send(m_sock, tempbuf[0], datasize, 0 );
    end;
      

  8.   

    5,真正的数据传送,用代理传送的时候,数据包的前面加上10个字节
    类似:
    procedure CopyDataHead( ptempbuf: PByte);
    var
      in_addr : TSockaddr;
      b : byte;
      p: PWord;
    begin
      addr.s_addr := inet_addr('202.220.33.333');//这个ip是服务器端的ip
        ptempbuf[0]^ := 0;
        ptempbuf[1]^ := 0;
        ptempbuf[2]^ := 0;
        ptempbuf[3]^ := 1;
        ptempbuf[4]^ := addr.S_un.S_un_b.s_b1;;
        ptempbuf[5]^ := addr.S_un.S_un_b.s_b2;
        ptempbuf[6]^ := addr.S_un.S_un_b.s_b3;
        ptempbuf[7]^ := addr.S_un.S_un_b.s_b4;
        p := PWord( PChar(ptempbuf)+8 );
        p^ := ServerUDPPort;//服务器的端口,就是你最终要发到那个服务器的端口。
        b := ptempbuf[8]^ ;
        ptempbuf[8]^ := ptempbuf[9]^;
        ptempbuf[9]^ := b;
    end;
      

  9.   

    非常感谢flyinwuhan(制怒·三思而后行)的回答
    是不是就是说udp模式下,不能通过http代理发送和接收数据呢?
      

  10.   

    非常感谢flyinwuhan(制怒·三思而后行)的回答
    谢谢!