procedure TRealMessengerX.SendIdentity; //验证身份
var
  LoginTime: Integer;
  CBLogin: TCBLogin;
  Buffer: array[1..2048] of char;   
  StrHttpProxySend, StrHttpProxyRecive: string;
begin
  if ClientTCP.Connected=false then  //窗体自带TCP控件连接没有打开的情况下……
    
  begin
   //  showmessage(trim(SystemSetForm.EDHostName.Text));
   // showmessage(SystemSetForm.EDHostName.Text);
    if inet_addr(PChar(HostIP))=INADDR_NONE then
      ClientTCP.Host:=HostName
    else
      ClientTCP.Host:=HostIP;
    ClientTCP.Port:=ServerPort;
    {ClientTCP.Host := trim(SystemSetForm.EDHostName.Text);
    ClientTCP.Port := StrToInt(SystemSetForm.EDHostName.Text);}
    try
      MConnect.Caption := '取消登录(&I)';
      Gauge.Progress := 0;
      PBLogin.Visible := True;
      LblLoging.Caption := '正在连接...';
      LblLoging.Visible := True;
      LblCancelLogin.Visible := True;      if ProxyCategory <> pcHTTP then  //代理种类如果不是HTTP,为真
      begin
        IdSocksInfo1.Version := TSocksVersion(ProxyCategory);
        IdSocksInfo1.Host := ProxyAddress;
        IdSocksInfo1.Port := ProxyPort;
        if ProxyUsername = '' then
        begin
          IdSocksInfo1.Authentication := saNoAuthentication;
        end
        else
        begin
          IdSocksInfo1.Authentication := saUsernamePassword;
          IdSocksInfo1.Username := ProxyUsername;
          IdSocksInfo1.Password := ProxyPassword;
        end;        LoginTime := 0;
        while LoginTime < 3 do
        try
          ClientTCP.Connect(8000);  //TCP尝试连接三次
          break;
        except
          Inc(LoginTime);
        end;
      end
      else
      begin
        IdSocksInfo1.Version := svNoSocks;
        StrHttpProxySend := Format('CONNECT %s:%d HTTP/1.0'#$d#$a#$d#$a + 'Host %s'#$d#$a, [ClientTCP.Host, ClientTCP.Port, ClientTCP.Host]);
        ClientTCP.Host := ProxyAddress;
        ClientTCP.Port := ProxyPort;
        ClientTCP.Connect(8000);
        ClientTCP.Write(StrHttpProxySend);  //写入字符HTTP代理发送字符串中
        StrHttpProxyRecive := ClientTCP.ReadLn; //(EOL); 读取信息,保存至HTTP代理接受字符串中
        ClientTCP.ReadLn;
        ClientTCP.ReadLn;
        if Copy(StrHttpProxyRecive, 1, 12) <> 'HTTP/1.0 200' then
        ClientTCP.Disconnect;
      end;    except
    end;    if not ClientTCP.Connected then
    begin
      ClientLogout;
      CoolTrayIcon.ShowBalloonHint('连接失败', '未能连接至服务器,请检查网络设置!', bitError, 10);
      exit;
    end;    ClientHandleThread := TClientHandleThread.Create; // 窗体TCP控件如果连接没有打开的情况下。激活线程开始工作
    ClientHandleThread.FreeOnTerminate := True; //线程如果推出,释放所有资源
    ClientHandleThread.Resume; //唤醒        if   ClientTCP.Connected = False
  end;//既然都没有保持连接,为什么还要用一个线程来读取服务器信息?  CBLogin.LoginName := LoginName; //用户名
  CBLogin.Password := Password; //密码
  CBLogin.State := LoginState; //状态:联机
  CBLogin.LocalIP := GetHostIP(''); //本机IP
  CBLogin.LocalPort := ClientTCP.Socket.Binding.Port;  //本机端口
  CBLogin.HaveAudioDevice := HaveAudioDevice;
  CBLogin.HaveVideoDevice := HaveVideoDevice;
  CBLogin.MACNO := MACNO;
  CBLogin.Version := 40000;  //版本
  Buffer[1] := skLogin; 
  CopyMemory(@Buffer[2], @CBLogin, SizeOf(CBLogin));
  ClientTCP.Socket.Send(Buffer, SizeOf(CBLogin) + 1); //将登录信息,用TCP方式,发送至登录服务器;
  LblMyState.Caption := '正在登录...';
end;
if ClientTCP.Connected=false then//这一句,既然没有保持连接,为什么还要用一个线程来读取服务器信息?

解决方案 »

  1.   

      if ClientTCP.Connected=false then  //窗体自带TCP控件连接没有打开的情况下……
        ClientHandleThread := TClientHandleThread.Create; // 窗体TCP控件如果连接没有打开的情况下。激活线程开始工作
        ClientHandleThread.FreeOnTerminate := True; //线程如果推出,释放所有资源
        ClientHandleThread.Resume; //唤醒        if   ClientTCP.Connected = False
      end;//既然都没有保持连接,为什么还要用一个线程来读取服务器信息?
      

  2.   

      if ClientTCP.Connected=false then  //窗体自带TCP控件连接没有打开的情况下……
        ClientHandleThread := TClientHandleThread.Create; // 窗体TCP控件如果连接没有打开的情况下。激活线程开始工作
        ClientHandleThread.FreeOnTerminate := True; //线程如果推出,释放所有资源
        ClientHandleThread.Resume; //唤醒        if   ClientTCP.Connected = False
      end;//既然都没有保持连接,为什么还要用一个线程来读取服务器信息?
      

  3.   

     ClientTCP.Connect(8000);  这里有连接啊 。
    所以线程开启 啊。