在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
TFileServerThread = class(TServerClientThread)
public procedure ClientExecute; override; end; { TFileServerThread }
procedure TFileServerThread.ClientExecute;
var Data : array[0..1023] of char; RecText : string; SocketStream : TWinSocketStream; begin While Not Terminated And ClientSocket.Connected Do
Try SocketStream := TWinSocketStream.Create(ClientSocket, 30000); Try FillChar(Data, SizeOf(Data), 0); If SocketStream.Read(Data, SizeOf(Data)) = 0 Then Begin // If we didn't get any data after xx seconds then close the connection ClientSocket.SendText('Timeout on Server'+#13#10); //Wait a little time to allow sending of text before disconnect 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; Except HandleException; End; end; procedure TForm1.ServerSocketGetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread); begin SocketThread := TFileServerThread.Create(False, ClientSocket); end; ----------------------------------------------------------------------------------------------------------------------------- delphi的帮助中有Writing client threads 和 Writing server threads代码示例。
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论