socksvr.pp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Program server;
  2. {
  3. Program to test Sockets unit by Michael van Canneyt and Peter Vreman
  4. Server Version, First Run sock_svr to let it create a socket and then
  5. sock_cli to connect to that socket
  6. }
  7. uses Linux,Sockets;
  8. const
  9. SPath='ServerSoc';
  10. Var
  11. FromName : string;
  12. Buffer : string[255];
  13. S : Longint;
  14. Sin,Sout : Text;
  15. procedure perror (const S:string);
  16. begin
  17. writeln (S,SocketError);
  18. halt(100);
  19. end;
  20. begin
  21. S:=Socket (AF_UNIX,SOCK_STREAM,0);
  22. if SocketError<>0 then
  23. Perror ('Server : Socket : ');
  24. UnLink(SPath);
  25. if not Bind(S,SPath) then
  26. PError ('Server : Bind : ');
  27. if not Listen (S,1) then
  28. PError ('Server : Listen : ');
  29. Writeln('Waiting for Connect from Client, run now sock_cli in an other tty');
  30. if not Accept (S,FromName,Sin,Sout) then
  31. PError ('Server : Accept : ');
  32. Reset(Sin);
  33. ReWrite(Sout);
  34. Writeln(Sout,'Message From Server');
  35. Flush(SOut);
  36. while not eof(sin) do
  37. begin
  38. Readln(Sin,Buffer);
  39. Writeln('Server : read : ',buffer);
  40. end;
  41. Unlink(SPath);
  42. end.