socksvr.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Program server;
  2. {
  3. $Id$
  4. This file is part of the Free Component Library (FCL)
  5. Copyright (c) 1999-2000 by the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. TUnixServerApp server program. This will listen on a socket till
  14. a client connects. You can connect by running the 'dsockcli' or
  15. 'sockcli' programs in another terminal.
  16. }
  17. uses ssockets;
  18. const
  19. SPath='ServerSoc';
  20. Type
  21. TUnixServerApp = Class(TObject)
  22. Private
  23. FServer : TUnixServer;
  24. Public
  25. Constructor Create(SockName : String);
  26. Destructor Destroy;override;
  27. Procedure OnConnect (Sender : TObject; Data : TSocketStream);
  28. Procedure Run;
  29. end;
  30. Constructor TUnixServerApp.Create(SockName : String);
  31. begin
  32. FServer:=TUnixServer.Create(SockName);
  33. FServer.OnConnect:=@OnConnect;
  34. end;
  35. Destructor TUNixServerApp.Destroy;
  36. begin
  37. FServer.Free;
  38. end;
  39. Procedure TUnixServerApp.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 TUnixServerApp.Run;
  52. begin
  53. FServer.StartAccepting;
  54. end;
  55. Var
  56. Application : TUnixServerApp;
  57. begin
  58. Application:=TUnixServerApp.Create(SPath);
  59. Application.Run;
  60. Application.Free;
  61. end.
  62. {
  63. $Log$
  64. Revision 1.2 2000-07-13 11:33:04 michael
  65. + removed logs
  66. }