我的服务端程序如下:
Procedure TFileServerThread.ClientExecute;
Var
Data: Array[0..1023] Of char;
RecText: String;
SocketStream: TWinSocketStream;
Begin
While Not Terminated And ClientSocket.Connected Do
begin
Try
SocketStream := TWinSocketStream.Create(ClientSocket, 30000);
if SocketStream.WaitForData(60000) then
begin
Try
FillChar(Data, SizeOf(Data), 0);
If SocketStream.Read(Data, SizeOf(Data)) = 0 Then
Begin
ClientSocket.SendText('Timeout on Server'+#13#10);
sleep(1);
ClientSocket.Close;
Terminate;
End;
RecText := Data;
If Length(RecText) > 2 Then
Delete(RecText, Pos(#13#10, RecText), 2); // Delete #13#10
If ClientSocket.Connected Then
Begin
ClientSocket.SendText(RecText);
SendMessage(Form1.Listbox1.Handle, LB_ADDSTRING, 0, Integer(PChar(RecText)));
PostMessage(Form1.Handle, CM_INCCOUNT, 0, 0);
End;
Finally
SocketStream.Free;
End;
end;
Except
//HandleException;
//showmessage('ERROR!!!!!!!!');
ClientSocket.Close;
Terminate;
End;
end;
End;
但是当程序运行的时候,会在If SocketStream.Read(Data, SizeOf(Data)) = 0 Then这一句报错:指定的网路名不再可用。我看过原来的帖子说:把
Except
//HandleException;
//showmessage('ERROR!!!!!!!!');
ClientSocket.Close;
Terminate;
End
这一段程序中的HandleException去掉,我现在已经把它去掉了,但是还是在
If SocketStream.Read(Data, SizeOf(Data)) = 0这一句报同样的错误,是在不知道怎么回事了,请各位大侠帮忙,谢谢!!!
单步跟踪看看吧,可能在执行中把ClientSocket关闭了,那么SocketStream创建不成功。
先调试通server,然后运行他,在来调试client。
--------------------------
新闻:
上海最快3月底推TD上网本导航:
博客园首页 知识库 新闻 招聘 社区 小组 博问 网摘 找找看
阅读(369) | 评论(0) | 转发(0) |