H
huajj
Unregistered / Unconfirmed
GUEST, unregistred user!
在sock线中或是在自己定义的线程中memo1显示内容非常非常慢,急需大家帮助解决。
调用线程:
procedure TMain_Form.ServerSocket1GetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
begin
SocketThread := TsecuServerThread.Create(true, ClientSocket,self.memo1);
SocketThread.FreeOnTerminate := True;
SocketThread.Resume;
end;
定义线程:
//侦听发起并接收应答处理线程
TsecuServerThread = class(TServerClientThread)
public
Constructor Create(T_Type:boolean;ClientSocket: TServerClientWinSocket;Memostat1:TMemo);
private
protected
Memoq:TMemo;
procedure ClientExecute;
override;
end;
主线程详细内容(有些内容有删除):
Constructor TsecuServerThread.Create(T_Type:boolean;ClientSocket: TServerClientWinSocket;Memostat1:TMemo);
begin
inherited Create(T_Type,ClientSocket);
Memoq := Memostat1;
end;
procedure TsecuServerThread.ClientExecute;
var
FDSet: TFDSet;
TimeVal: TTimeVal;
i: integer;
Ret: integer;
.......
TxReqPkg,TxAnsPkg: array [0..600] of char;
TxLen,Recv_Len: integer;
str:string;
begin
while not Terminated and ClientSocket.Connecteddo
begin
FD_ZERO(FDSet);
FD_SET(ClientSocket.SocketHandle, FDSet);
TimeVal.tv_sec := 0;
TimeVal.tv_usec := 500;
if (select(0, @FDSet, nil, nil, @TimeVal) >
0) and not Terminated then
if ClientSocket.ReceiveBuf(FDSet, -1) = 0 then
break
else
begin
//端口校验
if ClientSocket.LocalPort = cfg.scserver_port then
begin
// 创建 sockstream
ScktStream := TWinSocketStream.Create(ClientSocket, 1000);
fillmemory(@TxReqPkg,sizeof(TxReqPkg),32);
// 接收银行请求
Recv_Len := Recv_HsPkg(ClientSocket,scktStream,TxReqPkg);
// 接收错误,结束
if (Recv_Len <
0) then
begin
try
ScktStream.Free;
ClientSocket.Close;
except
end;
exit;
end;
copymemory(@BankReq_Trans,@TxReqPkg,sizeof(BankReq_Trans))
GetKeys;
Recv_Len:=recvpackage(BankReq_Trans);
if cfg.comm_pack=1 then
begin
Self.Memoq.Clear;
Self.Memoq.Lines.Add('************银行请求***********');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('交易时间(时分):');
Self.Memoq.Lines.Add('交易日期(月日):');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
end
Ret := Send_HsPkg(ClientSocket,scktStream,TxAnsPkg,Recv_Len);
// 发送失败
if (Ret = -1) or (Ret = -2) then
begin
try
scktstream.Free;
ClientSocket.Close;
except
end;
exit;
end;
// 关闭 socket
try
scktstream.Free;
ClientSocket.Close;
except
end;
end;
end;
end;
end;
调用线程:
procedure TMain_Form.ServerSocket1GetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
begin
SocketThread := TsecuServerThread.Create(true, ClientSocket,self.memo1);
SocketThread.FreeOnTerminate := True;
SocketThread.Resume;
end;
定义线程:
//侦听发起并接收应答处理线程
TsecuServerThread = class(TServerClientThread)
public
Constructor Create(T_Type:boolean;ClientSocket: TServerClientWinSocket;Memostat1:TMemo);
private
protected
Memoq:TMemo;
procedure ClientExecute;
override;
end;
主线程详细内容(有些内容有删除):
Constructor TsecuServerThread.Create(T_Type:boolean;ClientSocket: TServerClientWinSocket;Memostat1:TMemo);
begin
inherited Create(T_Type,ClientSocket);
Memoq := Memostat1;
end;
procedure TsecuServerThread.ClientExecute;
var
FDSet: TFDSet;
TimeVal: TTimeVal;
i: integer;
Ret: integer;
.......
TxReqPkg,TxAnsPkg: array [0..600] of char;
TxLen,Recv_Len: integer;
str:string;
begin
while not Terminated and ClientSocket.Connecteddo
begin
FD_ZERO(FDSet);
FD_SET(ClientSocket.SocketHandle, FDSet);
TimeVal.tv_sec := 0;
TimeVal.tv_usec := 500;
if (select(0, @FDSet, nil, nil, @TimeVal) >
0) and not Terminated then
if ClientSocket.ReceiveBuf(FDSet, -1) = 0 then
break
else
begin
//端口校验
if ClientSocket.LocalPort = cfg.scserver_port then
begin
// 创建 sockstream
ScktStream := TWinSocketStream.Create(ClientSocket, 1000);
fillmemory(@TxReqPkg,sizeof(TxReqPkg),32);
// 接收银行请求
Recv_Len := Recv_HsPkg(ClientSocket,scktStream,TxReqPkg);
// 接收错误,结束
if (Recv_Len <
0) then
begin
try
ScktStream.Free;
ClientSocket.Close;
except
end;
exit;
end;
copymemory(@BankReq_Trans,@TxReqPkg,sizeof(BankReq_Trans))
GetKeys;
Recv_Len:=recvpackage(BankReq_Trans);
if cfg.comm_pack=1 then
begin
Self.Memoq.Clear;
Self.Memoq.Lines.Add('************银行请求***********');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('交易时间(时分):');
Self.Memoq.Lines.Add('交易日期(月日):');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
Self.Memoq.Lines.Add('委托方式:');
end
Ret := Send_HsPkg(ClientSocket,scktStream,TxAnsPkg,Recv_Len);
// 发送失败
if (Ret = -1) or (Ret = -2) then
begin
try
scktstream.Free;
ClientSocket.Close;
except
end;
exit;
end;
// 关闭 socket
try
scktstream.Free;
ClientSocket.Close;
except
end;
end;
end;
end;
end;