一个windows下的socket服务器端程序,接收unix系统发送的数据包时,产生Socket 10053错误,windos发包却正常,求高手看看
socket服务端接收程序如下:procedure TdmMain.IdTCPServer1Execute(AThread: TIdPeerThread);
var
strlog,strcode:string;
ileng :integer;
tmpException: Exception;
begin
if Athread=nil then exit;
if Not AThread.Connection.Connected then exit;
if Athread.Terminated then exit;
//AThread.Connection.ReadTimeout:= 200; ,加上这句回出现 Read Timeout 得异常
try try
//接收流
try
strlog:=AThread.Connection.ReadString(19);
frmMain.mmo1.Lines.Add('收到数据包,包:'+strlog);
if strlog <> '' then
begin
ileng:=StrToIntDef(trim(LeftStr(strlog,6)),0);
strcode:=MidStr(strlog,7,7);
end;
(AThread.Data as TThreadData).FStrRevc:= athread.Connection.ReadString(ileng);
frmMain.mmo1.Lines.Add('收到数据包,包:'+(AThread.Data as TThreadData).FStrRevc);
except
//返回,解包错误
MakeErrorXmlStream((AThread.Data as TThreadData).FStrSend);
end;
{$IFDEF CONNDATA}
if ((AThread.Data as TThreadData).FStrRevc = '') or (Length((AThread.Data as TThreadData).FStrRevc) <> ileng) then
begin
MakeErrorXmlStream((AThread.Data as TThreadData).FStrSend);
end
else
begin
//处理接收到的流,并返回要发送的流
KentDealStream((AThread.Data as TThreadData).FStrRevc ,(AThread.Data as TThreadData).FStrSend);
end;
{$ELSE}
(AThread.Data as TThreadData).FStrSend:=(AThread.Data as TThreadData).FStrRevc;
frmMain.mmo1.Lines.Add('收到数据包,包:'+(AThread.Data as TThreadData).FStrRevc);
{$ENDIF}
//发送流
// AThread.Connection.OpenWriteBuffer(); strlog:=inttostr(Length((AThread.Data as TThreadData).FStrSend));
if Length(strlog) =5 then strlog:=strlog+' '
else if Length(strlog) =4 then strlog:=strlog+' '
else if Length(strlog) =3 then strlog:=strlog+' '
else if Length(strlog) =2 then strlog:=strlog+' '
else if Length(strlog) =1 then strlog:=strlog+' '
else if Length(strlog) >6 then strlog:=leftstr(strlog,6); (AThread.Data as TThreadData).FStrSend:= strlog+ strcode+'006 '+ (AThread.Data as TThreadData).FStrSend; AThread.Connection.Write((AThread.Data as TThreadData).FStrSend);
// AThread.Connection.CloseWriteBuffer();
finally end;
except
AThread.Connection.Disconnect;
tmpException := ExceptObject as Exception;
oLogfile.addtolog('IdTCPServer1Execute 异常!'
+' 原因:'+TmpException.Message);
end;
socket服务端接收程序如下:procedure TdmMain.IdTCPServer1Execute(AThread: TIdPeerThread);
var
strlog,strcode:string;
ileng :integer;
tmpException: Exception;
begin
if Athread=nil then exit;
if Not AThread.Connection.Connected then exit;
if Athread.Terminated then exit;
//AThread.Connection.ReadTimeout:= 200; ,加上这句回出现 Read Timeout 得异常
try try
//接收流
try
strlog:=AThread.Connection.ReadString(19);
frmMain.mmo1.Lines.Add('收到数据包,包:'+strlog);
if strlog <> '' then
begin
ileng:=StrToIntDef(trim(LeftStr(strlog,6)),0);
strcode:=MidStr(strlog,7,7);
end;
(AThread.Data as TThreadData).FStrRevc:= athread.Connection.ReadString(ileng);
frmMain.mmo1.Lines.Add('收到数据包,包:'+(AThread.Data as TThreadData).FStrRevc);
except
//返回,解包错误
MakeErrorXmlStream((AThread.Data as TThreadData).FStrSend);
end;
{$IFDEF CONNDATA}
if ((AThread.Data as TThreadData).FStrRevc = '') or (Length((AThread.Data as TThreadData).FStrRevc) <> ileng) then
begin
MakeErrorXmlStream((AThread.Data as TThreadData).FStrSend);
end
else
begin
//处理接收到的流,并返回要发送的流
KentDealStream((AThread.Data as TThreadData).FStrRevc ,(AThread.Data as TThreadData).FStrSend);
end;
{$ELSE}
(AThread.Data as TThreadData).FStrSend:=(AThread.Data as TThreadData).FStrRevc;
frmMain.mmo1.Lines.Add('收到数据包,包:'+(AThread.Data as TThreadData).FStrRevc);
{$ENDIF}
//发送流
// AThread.Connection.OpenWriteBuffer(); strlog:=inttostr(Length((AThread.Data as TThreadData).FStrSend));
if Length(strlog) =5 then strlog:=strlog+' '
else if Length(strlog) =4 then strlog:=strlog+' '
else if Length(strlog) =3 then strlog:=strlog+' '
else if Length(strlog) =2 then strlog:=strlog+' '
else if Length(strlog) =1 then strlog:=strlog+' '
else if Length(strlog) >6 then strlog:=leftstr(strlog,6); (AThread.Data as TThreadData).FStrSend:= strlog+ strcode+'006 '+ (AThread.Data as TThreadData).FStrSend; AThread.Connection.Write((AThread.Data as TThreadData).FStrSend);
// AThread.Connection.CloseWriteBuffer();
finally end;
except
AThread.Connection.Disconnect;
tmpException := ExceptObject as Exception;
oLogfile.addtolog('IdTCPServer1Execute 异常!'
+' 原因:'+TmpException.Message);
end;
解决方案 »
- delphi中调用DLL出错
- ADO和SYBASE如何建立数据库连接?很急,请各位大虾帮忙
- adoquery1.LoadFromFile()是做什么用的
- [大龍駒]干掉小日本,反對鬼子“常任”,抵制日貨!
- quickreport小問題
- 讨论一下:Delphi开发中为提高开发效率,大家用了哪些辅助工具(像著名的GExpert)?
- 关于delphi调用vc中dll出错的问题,大家帮忙看看
- DELPHI 中 数 据 库 网 格DBGrid 的 灵 活 修 饰
- 我有一個軟件﹐ 有個問題﹐如何將'Led1'提取為Led1,請各位多多指教﹗﹗﹗
- 怎样引导mis的登陆窗口?能否讲的详细写?
- 送分题。IdIcmpClient1的网络ping包为题
- 关于摄像头控制视频显示区域的问题?
坛子里也有一些
http://topic.csdn.net/t/20030409/11/1637501.html
http://topic.csdn.net/u/20090225/16/672c0cd5-d4d7-4a81-80f4-7e74b17cf235.html