isocksvr.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Program server;
  2. {
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. TInetServer server program. This will listen on port 4100 till
  13. a client connects. You can connect by running the 'isockcli' or
  14. 'dsockcli -i' programs in another terminal.
  15. }
  16. {$mode objfpc}{$H+}
  17. uses ssockets;
  18. const
  19. ThePort=4100;
  20. Type
  21. TINetServerApp = Class(TObject)
  22. Private
  23. FServer : TInetServer;
  24. Public
  25. Constructor Create(Port : longint);
  26. Destructor Destroy;override;
  27. Procedure OnConnect (Sender : TObject; Data : TSocketStream);
  28. Procedure Run;
  29. end;
  30. Constructor TInetServerApp.Create(Port : longint);
  31. begin
  32. FServer:=TINetServer.Create(Port);
  33. FServer.OnConnect:=@OnConnect;
  34. end;
  35. Destructor TInetServerApp.Destroy;
  36. begin
  37. FServer.Free;
  38. end;
  39. Procedure TInetServerApp.OnConnect (Sender : TObject; Data : TSocketStream);
  40. Var Buf : ShortString;
  41. Count : longint;
  42. begin
  43. Repeat
  44. Count:=Data.Read(Buf[1],255);
  45. SetLength(Buf,Count);
  46. Write('Server got : ',Buf);
  47. Until (Count=0) or (Pos('QUIT',Buf)<>0);
  48. Data.Free;
  49. FServer.StopAccepting;
  50. end;
  51. Procedure TInetServerApp.Run;
  52. begin
  53. FServer.StartAccepting;
  54. end;
  55. Var
  56. Application : TInetServerApp;
  57. begin
  58. Application:=TInetServerApp.Create(ThePort);
  59. Application.Run;
  60. Application.Free;
  61. end.