idtcpserver 如何判断idtcpclient的连接非正常中断 ( 积分: 100 )

  • 主题发起人 主题发起人 jimmypeng
  • 开始时间 开始时间
J

jimmypeng

Unregistered / Unconfirmed
GUEST, unregistred user!
大哥们:
我用idtcpclient 和 idtcpserver 开发了一个通信程序
**--- idtcpclent 端
IdTcpClient.Connect(5000);
while AQrySendSms.Eof=False do
begin
//给服务器端送值
....
....
IdTcpClient.OpenWriteBuffer(-1);
IdTcpClient.WriteBuffer(MySendingRecord,sizeof(MySendingRecord),True);
IdTcpClient.CloseWriteBuffer;
//接收服务器端返回值
....
....
IdTcpClient.ReadBuffer(MyReceivingRecord,SizeOf(MyReceivingRecord));
AQrySendSms.Next;
end;
***---- 服务器端
....
....
try
if isMobiFinish = False then
begin
AThread.Connection.ReadBuffer(MyReceivingRecord,SizeOf(MyReceivingRecord));
....
....
AThread.Connection.OpenWriteBuffer(-1);
AThread.connection.WriteBuffer(MySendingRecord,SizeOfMySendingRecord),True);
AThread.Connection.CloseWriteBuffer;
...
...
end;
except
on E:Exception do
LBLog.Items.Add(DateTimeToStr(now) + ' ' + Athread.Connection.Socket.Binding.PeerIP + ' 错误: ' + E.Message);
end;

问题: 1.在服务器端的 Exception 代码后面有时会出现" connection closed gracefully "错误, 然后客户端就没有任何反映,资料就不能传送.请问这是什么原因.该如何改善客户端和服务器端. 一般这个错误只在DELPHI编译环境才会出来,可在运行时也会有.
2. 客户端用服务器怎么样可以检测到他们的连接已经非正常中断.
 
大哥们:
我用idtcpclient 和 idtcpserver 开发了一个通信程序
**--- idtcpclent 端
IdTcpClient.Connect(5000);
while AQrySendSms.Eof=False do
begin
//给服务器端送值
....
....
IdTcpClient.OpenWriteBuffer(-1);
IdTcpClient.WriteBuffer(MySendingRecord,sizeof(MySendingRecord),True);
IdTcpClient.CloseWriteBuffer;
//接收服务器端返回值
....
....
IdTcpClient.ReadBuffer(MyReceivingRecord,SizeOf(MyReceivingRecord));
AQrySendSms.Next;
end;
***---- 服务器端
....
....
try
if isMobiFinish = False then
begin
AThread.Connection.ReadBuffer(MyReceivingRecord,SizeOf(MyReceivingRecord));
....
....
AThread.Connection.OpenWriteBuffer(-1);
AThread.connection.WriteBuffer(MySendingRecord,SizeOfMySendingRecord),True);
AThread.Connection.CloseWriteBuffer;
...
...
end;
except
on E:Exception do
LBLog.Items.Add(DateTimeToStr(now) + ' ' + Athread.Connection.Socket.Binding.PeerIP + ' 错误: ' + E.Message);
end;

问题: 1.在服务器端的 Exception 代码后面有时会出现" connection closed gracefully "错误, 然后客户端就没有任何反映,资料就不能传送.请问这是什么原因.该如何改善客户端和服务器端. 一般这个错误只在DELPHI编译环境才会出来,可在运行时也会有.
2. 客户端用服务器怎么样可以检测到他们的连接已经非正常中断.
 
如果网络不稳定的话,Client和Server的连接就断掉了,然后2端都没办法发现.有什么办法可以发现连接已断掉.
 
后退
顶部