H
hxygod
Unregistered / Unconfirmed
GUEST, unregistred user!
我用阻塞模式通讯,当客户端意外中断后,服务器端报错:“Read error64,指定的网络名不再可用!”,正常情况下不管是断开链接还是发送数据都可以,哪位大侠知道我在服务器端如何屏蔽这个系统错误吗,兄弟我已经被这个问题困惑有一个星期了,就是不知道怎么处理
服务器端接收:
procedure TServerRead.ClientExecute;
var
Stream : TWinSocketStream;
Buf : array[1 .. 2048] of Char;
len : integer;
begin
tmp_Stream := TMemoryStream.Create;
while (not Terminated) and ClientSocket.Connected do
begin
try
Stream := TWinSocketStream.Create(ClientSocket, 1000);
FillChar(Buf, SizeOf(Buf), 0);
try
if Stream.WaitForData(1000) and ( ClientSocket.Connected) then
begin
len:=Stream.Read(Buf, SizeOf(Buf));//Debug就是在这句话报错
if len= 0 then
begin
ClientSocket.Close;
Terminate ;
end;
end
else
begin
ClientSocket.Close;
Terminate;
end;
except
showmessage('Error!');
end;
except
HandleException;
end;
end;
end;
客户端发送:
procedure TClientWrite.Execute;
var
MyStream : TWinsocketStream;
buffer : array[1 .. 2048] of Char;
i,j : integer;
s:string;
begin
FillChar(buffer, SizeOf(buffer), 's');
MyStream := TWinsocketStream.Create(Form1.CS.Socket,50000);
While (Not Terminated) and (Form1.CS.Active) do
begin
s:='hello!';
StrPCopy(@buffer, S);
j:=length(s);
i :=MyStream.Write(buffer,j);
if i = 0 then
Form1.CS.Close;
Terminate;
end;
MyStream.Destroy;
end;
服务器端接收:
procedure TServerRead.ClientExecute;
var
Stream : TWinSocketStream;
Buf : array[1 .. 2048] of Char;
len : integer;
begin
tmp_Stream := TMemoryStream.Create;
while (not Terminated) and ClientSocket.Connected do
begin
try
Stream := TWinSocketStream.Create(ClientSocket, 1000);
FillChar(Buf, SizeOf(Buf), 0);
try
if Stream.WaitForData(1000) and ( ClientSocket.Connected) then
begin
len:=Stream.Read(Buf, SizeOf(Buf));//Debug就是在这句话报错
if len= 0 then
begin
ClientSocket.Close;
Terminate ;
end;
end
else
begin
ClientSocket.Close;
Terminate;
end;
except
showmessage('Error!');
end;
except
HandleException;
end;
end;
end;
客户端发送:
procedure TClientWrite.Execute;
var
MyStream : TWinsocketStream;
buffer : array[1 .. 2048] of Char;
i,j : integer;
s:string;
begin
FillChar(buffer, SizeOf(buffer), 's');
MyStream := TWinsocketStream.Create(Form1.CS.Socket,50000);
While (Not Terminated) and (Form1.CS.Active) do
begin
s:='hello!';
StrPCopy(@buffer, S);
j:=length(s);
i :=MyStream.Write(buffer,j);
if i = 0 then
Form1.CS.Close;
Terminate;
end;
MyStream.Destroy;
end;