有网络高手在线不?请问一个问题 ( 积分: 100 )

  • 主题发起人 主题发起人 dkq811230
  • 开始时间 开始时间
D

dkq811230

Unregistered / Unconfirmed
GUEST, unregistred user!
有那个用过dxsock没有。有写过服务端没
var
strTmp,StrLog:string;
intPos:integer;
IntLen,intLenTerminate:integer;
strData:string;
varValue:Variant;
num:integer;
strReceiveData,strTheEnd:string;
ReceBuff: Array [0..MAX_BUFSIZE-1] of char;
begin
try
ClientThread.Socket.SetNagle(true);
ClientNewConnect(ClientThread);
try
while ClientThread.Socket.Connected do
begin
if ClientThread.Socket.Readable then
begin
If ClientThread.Socket.CharactersToRead=0 then break; // disconnect
FillChar(ReceBuff,Sizeof(ReceBuff),#0);
num:=ClientThread.Socket.CharactersToRead;
ClientThread.Socket.ReceiveBuf(ReceBuff,num) ;
strReceiveData:=string(ReceBuff);
strData:=strReceiveData;
IntLen:=strtoIntdef(copy(strData,1,4),0)+4;
intLenTerminate:=length(gcstrTerminate);
strTheEnd:=copy(strData,IntLen-intLenTerminate+1,intLenTerminate);
while strTheEnd=gcstrTerminate do
begin
strTmp:=copy(strData,1,IntLen+intLenTerminate-1);
delete(strData,1,IntLen+intLenTerminate-1);
ProcessMsg(ClientThread.Socket,strTmp);
IntLen:=strtoIntdef(copy(strData,1,4),0)+4;
strTheEnd:=copy(strData,IntLen-intLenTerminate+1,intLenTerminate);
end;
{$IFDEF Write}
try
StrLog:='来自主机: '+ ClientThread.Socket.PeerIPAddress
+stringofchar(' ',3)+stringofchar(' ',2)+
'消息长度:'+inttostr(Length(strReceiveData))+stringofchar(' ',4)+
'消息内容:'+strReceiveData;
WriteToMemo(memReceData,StrLog);
except
end;
{$ENDIF}
end
else
begin
DXString.DoSleepEx(1);
DXString.ProcessWindowsMessageQueue;
end;
end;
finally
ClientCloseConnect(ClientThread);
end;
except
on e:Exception do
begin
ClientThread.Terminate;
WriteToMemo(memError,'错误信息:'+e.Message );
end;
end;
 
有时报不知是啥错误?
 
后退
顶部