socksvr.pp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. TUnixServerApp server program. This will listen on a socket till
  13. a client connects. You can connect by running the 'dsockcli' or
  14. 'sockcli' programs in another terminal.
  15. }
  16. {$mode objfpc}{$h+}
  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.