打印本文 打印本文 关闭窗口 关闭窗口
用Delphi设计代理服务器[正确文章]
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3896  更新时间:2009/4/23 18:42:48  文章录入:mintao  责任编辑:mintao
p;               {判断是哪一个会话}
      if session[i-1].Used and (session[i-1].SS_Handle=socket.sockethandle) then
          begin
             session[i-1].request_str:=socket.ReceiveText;  {保存请求数据}
             tmp:=session[i-1].request_str;                 {存放到临时变量}
             memo1.lines.add(tmp);
             j:=pos(char(13)+char(10),tmp);                 {一行标志}
             while j>0 do                       {逐行扫描请求文本,查找主机地址}
                begin
                   line:=copy(tmp,1,j-1);                  {取一行}
                   delete(tmp,1,j+1);                      {删除一行}
                   j:=pos(''''Host'''',line);                    {主机地址标志}
                   if j>0 then
                      begin
                         delete(line,1,j+5);               {删除前面的无效字符}
                         j:=pos('''':'''',line);
                         if j>0 then
                            begin
                               host:=copy(line,1,j-1);
                               delete(line,1,j);
                               try
                                  port:=strtoint(line);
                               except
                                  port:=80;
                               end;
                            end
                         else
                            begin
                               host:=trim(line);                 {获取主机地址}
                               port:=80;
                            end;
                         if not session[i-1].remote_connected then  {假如远征尚未连接}
                            begin
                               session[i-1].Request:=true;      {置请求数据就绪标志}
                               session[i-1].CSocket.host:=host;  {设置远程主机地址}
                               session[i-1].CSocket.port:=port;     {设置端口}
                               session[i-1].CSocket.active:=true;   {连接远程主机}
                               session[i-1].Lookingup:=true;        {置标志}
                               session[i-1].LookupTime:=0;          {从0开始计时}
                            end
                         else
                            {假如远程已连接,直接发送请求}
                            session[i-1].CSocket.socket.sendtext(session[i-1].request_str);                                   
                         break;                        {停止扫描请求文本}
                      end;
                   j:=pos(char(13)+char(10),tmp);           {指向下一行}
                end;
             break;                    {停止循环}
          end;
end;

file://当连接远程主机成功时…
procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
var
i: integer;
begin
   for i:=1 to sessions do
      if (session[i-1].CSocket.socket.sockethandle=socket.SocketHandle) and session[i-1].Used then
         begin
            session[i-1].CSocket.tag:=socket.So

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口