服务器端
procedure TForm1.ServerConnect(AThread: TIdPeerThread);
begin
Athread.Connection.ReadBuffer(KR_login,sizeof(KR_login));
if (KR_login.Name = '1111') and (KR_login.Password = '1111') then
memo1.lines.add('登陆成功') else begin
memo1.lines.add('登陆失败');
Athread.Connection.Disconnect;
end;
end;
客户端procedure TForm1.Button1Click(Sender: TObject);
begin
Client.Host := ServiceIp.Text;
Client.Port := StrToint(Serviceport.Text);
Client.Connect(5000);
Login(Client,L_name.Text,L_pass.Text);
end;procedure TForm1.Login(Icon: TIdTCPClient; Name,password: String);
var
Lbuff: TKR_login;
begin
Lbuff.Name := name;
Lbuff.Password := password;
Icon.Writebuffer(Lbuff,sizeof(lbuff));
end;现的问题是:在登际不成功的时候,服务器断开与客户端的连结,但是现在发现如果第一次登陆不成功的话,第二次登陆客户端就出现already connected 错误提示,,感觉Athread.Connection.Disconnect;没有执行,但是 memo1.lines.add('登陆失败');正常显示,问下哥哥可哥们,我到底该怎么断开连结
procedure TForm1.ServerConnect(AThread: TIdPeerThread);
begin
Athread.Connection.ReadBuffer(KR_login,sizeof(KR_login));
if (KR_login.Name = '1111') and (KR_login.Password = '1111') then
memo1.lines.add('登陆成功') else begin
memo1.lines.add('登陆失败');
Athread.Connection.Disconnect;
end;
end;
客户端procedure TForm1.Button1Click(Sender: TObject);
begin
Client.Host := ServiceIp.Text;
Client.Port := StrToint(Serviceport.Text);
Client.Connect(5000);
Login(Client,L_name.Text,L_pass.Text);
end;procedure TForm1.Login(Icon: TIdTCPClient; Name,password: String);
var
Lbuff: TKR_login;
begin
Lbuff.Name := name;
Lbuff.Password := password;
Icon.Writebuffer(Lbuff,sizeof(lbuff));
end;现的问题是:在登际不成功的时候,服务器断开与客户端的连结,但是现在发现如果第一次登陆不成功的话,第二次登陆客户端就出现already connected 错误提示,,感觉Athread.Connection.Disconnect;没有执行,但是 memo1.lines.add('登陆失败');正常显示,问下哥哥可哥们,我到底该怎么断开连结
解决方案 »
- 如何实现NT服务程序可视化
- 如何真正模拟鼠标的运动?需要运动轨迹也模拟出来而不仅仅是setcursorpos
- 请问各位老兄,怎么获取摄像头的的视频并把获得的数据保存为连续的文件(*.dat,*.mpeg,)呀?
- 2000下设计的界面在98下变大的问题
- 在Delphi程序中怎样调用系统功能问题
- 谁有reportmachine的rm3.rar文件的解压缩密码,烦请告之,感激不尽,谢谢!
- 再谈谈日期时间的导入
- 急急~~~~,TOleContainer如何使用?
- 请问如何访问另一个运行中的程序中的内存数据呢?
- 请问,TDBEdit和TMonthCalendar如何配合使用?TMonthCalendar的用法?
- 问题重发<上次所谓的COM高手一一败下阵来,入门问题,难道所谓的高手还没入门吗?荒唐!!!
- 一个关于toolbar的很菜的问题
procedure TForm1.ServerConnect(AThread: TIdPeerThread);
begin
Athread.Connection.ReadBuffer(KR_login,sizeof(KR_login));
if (KR_login.Name = '1111') and (KR_login.Password = '1111') then
memo1.lines.add('登陆成功') else begin
memo1.lines.add('登陆失败');
AThread.Writeln('failedlogin'); //这里给客户端发个通知消息
Athread.Connection.Disconnect;
end;
end;客户端
用timer或在线程里:
var
s : string; s := idtcpclient1.readln();
if s = 'failedlogin' then
idtcpclient1.disconnect;大概就这意思,代码自己写。
if connected then DisConnect;
Host := '127.0.0.1';
Port := 9999;
Connect;
这是Indy Demos里的用法。
这样就没有问题了
==========================
连接前我会加上这一段
with IdTCPClient1 do
if connected then DisConnect;
Host := '127.0.0.1';
Port := 9999;
Connect;
这是Indy Demos里的用法。
这样就没有问题了