请高手帮忙:在ctBloching方式下,TwinSocketStream.Create(clientsocket.socket,1000)超时后执行哪些动作呢

H

hcai

Unregistered / Unconfirmed
GUEST, unregistred user!
请高手帮忙:在ctBloching方式下,TwinSocketStream.Create(clientsocket.socket,1000)超时后执行哪些动作呢?谢谢。 (100分)<br />我想在TwinsocketStream超时后执行哪些过程。
 
超时后断开连接。
 
to youngSun:
但我要把:发出去的数据但没有收到的数据回写入数据,即回写成超时,
程序:

thread1.FreeOnTerminate := TRUE;
thread1.Resume;

SckStream := TwinSocketStream.Create(BIQ2002SCK.clientSCK.Socket,TimeOut);
recTime :=0;
sckstream.
with BIQ2002SCK do
begin //

Buf_Length := 2*Length(send_bag1^) +1;

fun_type:=copy(send_bag1^,4,2);
fun_bankID := copy(send_bag1^,6,16);
fun_date := copy(send_bag1^,22,8);
fun_Time := copy(send_bag1^,30,6);
//////////////////////////////////////////////////////发送过程
label9.Font.Color:=$00FF0000;

for p:=0 to repeatTimes do
begin
try
teststr :=send_bag1^;
SendSucc:=SckStream.Write(pwidechar(teststr)^,length(teststr)+1);

except
showmessage('error');
clientSCK.Close;
SCKStream.Free;
end;

if SendSucc>0 then
begin
sendCount_tab.Text :=inttostr(strtoint(sendCount_tab.Text)+1);

repeat // and(runFlag = 'free')

if (updatelibflag = 'free')and(runFlag = 'free') then
begin

updatelibflag:='busy'; runFlag:='busy';
updateLIB(fun_type,fun_bankID);

end;

until updateLibFlag='free';

if fun_type='KF' then //insert : grid...
BagType:= '收费';
if fun_type='FK' then
BagType:= '退费';
if fun_type='CZ' then
BagType:='冲正';
if fun_type='ZZ'then
BagType:='对总帐';
if fun_type='DZ'then
BagType:='对明细';
sendStatus := '成功';

jelsID:=fun_bankid; //交易流水号
JEDATE:=copy(fun_date,1,4)+'-'+copy(fun_date,5,2)+'-'+copy(fun_date,7,8); //交易日期
JETIME:=copy(fun_time,1,2)+':'+copy(fun_time,3,2)+':'+copy(fun_time,5,2); //交易时间

send_State:='1';
insert_grid_bag(''); //插入表格;
send_State:='0';

break; //发送成功退出循环
end; //end: if....
end; //end : for...

////////////////////////////////////////////////////////////接收过程

new(recBuf);
FillChar(rec, 1024, 0);
while (not Terminated) and (clientSCK.Active) do
begin
try
recTime:=recTime+1000;
if recTime>=TimeOut*1000 then break; //进入超时控制
if SCKStream.WaitForData(1000) then
if SCKStream.Read(rec, Length(rec)+1) = 0 then
begin
recTime:=recTime+1000;
break;
end
else if length(rec)>2 then
begin
 
不好意思,我其实是个菜鸟,只是近段时间用到TCP/IP编程,看了一些东西。
一点建议,是否可以设一个标志变量,在断开时检查,然后执行回写数据库的操作。
帮你提前一下,让真正的高手帮你看看。
 
哈哈,你的超时时间也设得太短了吧,一般情况每一笔交易是一秒,但是超过5,6秒的情况
当然也会出现,当交易量大的时候,或者网络出现不稳定时都会超过2-5秒,而且你要是设
为10秒并不会影响交易的速度,何乐而不为呢?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部