8
8541051
Unregistered / Unconfirmed
GUEST, unregistred user!
我的服务端用的是TIdTCPServer控件,客户端用的是TClientSocket控件,是万不得已的。理论上是没有问题的,但是数据量大的时候往往会出现一些问题,TClientSocket接收的时候会多受到一个信息,经测试这个信息是个空的值,我的代码如下,高手请看一下问题在哪里。
客户端:
with TClientSocket.Create(nil) do
//with TIdTCPClient.Create(nil) do
try
Host := Form1.NewServerIp;
Port := Form1.NewServerPort;
ClientType := ctBlocking;
try
Open;
//Connect ;
//showmessage(inttostr(Sizeof(NewDataOr)));
Socket.SendBuf(NewDataOr, Sizeof(NewDataOr));
Socket.ReceiveBuf(R,Sizeof(R));
Form1.Edit1.Text := IntToStr(StrToInt(Form1.Edit1.Text)+1);
//WriteBuffer(NewDataOr, Sizeof(NewDataOr));
//ReadBuffer(R,4);
//Disconnect;
//Socket.Close;
Close ;
except
on E:Exception do
begin
if E.Message <> 'Connection Closed Gracefully.' then
begin
Form1.glog.WriteLog('向接口网关发送彩票数据失败!卡号:'+CardId +',原因:'+ E.Message, True); //写入log文件中
mstr := '向接口网关发送彩票数据失败!卡号:'+CardId +',原因:'+ E.Message;
Synchronize(DisplayMemo);
DataResponseHead^.Flag := 10; //返回结果10
Result := 1;
//Socket.Close;
Close ;
exit;
end;
//exit;
end;
end;
finally
Free;
end;
if R='0000' then //‘0000’是成功
begin
DataResponseHead^.Flag := 0;
Result := 0;
Form1.Edit3.Text := IntToStr(Zs*2+StrToInt(Form1.Edit3.Text));
exit;
end;
if R='' then //问题出在这里,不应该有''
begin
Form1.Edit2.Text := IntToStr(StrToInt(Form1.Edit2.Text)+1);
Form1.glog.WriteLog('接口网关回执空值,卡号:'+CardId +','+IntTostr(Zs)+'注', True); //写入log文件中
mstr := '接口网关回执空值!卡号:'+CardId +','+IntTostr(Zs)+'注';//+R+ManId+DQ+Pwd+PlayName;
Synchronize(DisplayMemo);
DataResponseHead^.Flag := 10; //返回结果10
Result := 9;
Exit;
end;
服务端:TIdTCPServer的OnExecute事件
……
R := '0000';
LogMsg := '向合并专用机发送票数据成功!卡号:'+Pn^.PhoneCordNo;
WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg); //写日值,没问题
AThread.Connection.WriteBuffer(R,Sizeof(R));
注:R为array [0..3] of Char;
客户端:
with TClientSocket.Create(nil) do
//with TIdTCPClient.Create(nil) do
try
Host := Form1.NewServerIp;
Port := Form1.NewServerPort;
ClientType := ctBlocking;
try
Open;
//Connect ;
//showmessage(inttostr(Sizeof(NewDataOr)));
Socket.SendBuf(NewDataOr, Sizeof(NewDataOr));
Socket.ReceiveBuf(R,Sizeof(R));
Form1.Edit1.Text := IntToStr(StrToInt(Form1.Edit1.Text)+1);
//WriteBuffer(NewDataOr, Sizeof(NewDataOr));
//ReadBuffer(R,4);
//Disconnect;
//Socket.Close;
Close ;
except
on E:Exception do
begin
if E.Message <> 'Connection Closed Gracefully.' then
begin
Form1.glog.WriteLog('向接口网关发送彩票数据失败!卡号:'+CardId +',原因:'+ E.Message, True); //写入log文件中
mstr := '向接口网关发送彩票数据失败!卡号:'+CardId +',原因:'+ E.Message;
Synchronize(DisplayMemo);
DataResponseHead^.Flag := 10; //返回结果10
Result := 1;
//Socket.Close;
Close ;
exit;
end;
//exit;
end;
end;
finally
Free;
end;
if R='0000' then //‘0000’是成功
begin
DataResponseHead^.Flag := 0;
Result := 0;
Form1.Edit3.Text := IntToStr(Zs*2+StrToInt(Form1.Edit3.Text));
exit;
end;
if R='' then //问题出在这里,不应该有''
begin
Form1.Edit2.Text := IntToStr(StrToInt(Form1.Edit2.Text)+1);
Form1.glog.WriteLog('接口网关回执空值,卡号:'+CardId +','+IntTostr(Zs)+'注', True); //写入log文件中
mstr := '接口网关回执空值!卡号:'+CardId +','+IntTostr(Zs)+'注';//+R+ManId+DQ+Pwd+PlayName;
Synchronize(DisplayMemo);
DataResponseHead^.Flag := 10; //返回结果10
Result := 9;
Exit;
end;
服务端:TIdTCPServer的OnExecute事件
……
R := '0000';
LogMsg := '向合并专用机发送票数据成功!卡号:'+Pn^.PhoneCordNo;
WriteLog(AThread.ThreadID,ListBox1.Items,LogMsg); //写日值,没问题
AThread.Connection.WriteBuffer(R,Sizeof(R));
注:R为array [0..3] of Char;