Socket. Net

  Example of reading the main page mysite.org :

(nil  let ((s ('socket  newobject)))
  (s  connect 80  "mysite.org")
  (s  write (("GET /index.html HTTP/1.1"  + (13 char) (10 char)
        "Host: mysite.org"  (13 char) (10 char)
        (13 char) (10 char))  byte-vector))
  (nil  let (buf  (bufsize 1024)  res)
    (nil  setq  buf ('byte-vector newobject bufsize))
    (nil do-while
      (nil  setq  res (s  read  buf bufsize))
      (nil  if  (nil  numberp res)
        (nil  progn
          (res  for*  i
            (cout write ((buf elt i)  char)))
          (res  > 0))
        (nil  progn
          (cout writeln "Error: " res)
          false))))
  (s  close))

  Connect using port 80 to the site mysite.org. Sending a data packet to the syntax and order of HTML standard. Reading response packets until the packets are not empty. Closure connection.

  For networking within the system using sockets UNIX. The file system uses a file as a point of connection. But the data is transferred through the buffers.

(nil  let ((socketname  (nil  const "My Socket"))
    (lockcout ('lock  newobject)))
  (nil  let ((unlink-error  (socketname unlink)))
    (nil  if  unlink-error
      (cout writeln "unlink(" socketname  ")="  unlink-error)
      (cout writeln "unlink(" socketname  ")=OK"))) ; let unlink-error
  (nil  fork
    (nil  try
    ; Client
    (nil  let ((sc  ('socket  newobject)) o s c)
      (sc open  "UNIX"  "STREAM")
      (lockcout progn (cout writeln "Client: open = " o))
      (nil  let (ce)
        (nil  do-while
          (lockcout progn (cout writeln "Client: connect..."))
          (nil  setq  ce  (sc connect socketname))
          (nil  if  ce
            (nil  progn
              (lockcout progn (cout writeln "Client connect: " ce))
              (1  sleep))
            (lockcout progn (cout writeln "Client connect: OK")))
          ce) ; do-while
        ) ; let ce
      (lockcout progn (cout writeln "The client sends a message to the server: Hi!"))
      ('s set (sc write "Hi!"))
      (lockcout progn (cout writeln "The client sent the " s " bytes"))
      (nil  let ((buf ('byte-vector newobject 100)) r)
        ('r set (sc read  buf))
        (lockcout progn (cout writeln "The client received a message size " r))) ; let buf
      ('c set (sc close))
      (lockcout progn (cout writeln "The client closed the connection to the server : " c))) ; let sc client
    nil
    (nil  progn 
      (cerr writeln "Client:EvalHistory[") 
      ((nil  exception-history) for*  history-i 
        (cerr print history-i)) 
      ((cerr writeln "]")  
        write "Error: ")  
      (nil  let ((exv (nil  exception)))  
        (nil  if  (nil  consp exv)  
          (nil  apply cerr  'writeln  exv)  
          (cerr writeln exv)))
      nil)
    ) ; try
    ) ; fork
  ; Server
  (nil  let ((sc  ('socket  newobject)) l b o a s u c c2)
    ('o set (sc open  "UNIX"  "STREAM"))
    (lockcout progn (cout writeln "Server: open = " o))
    (sc bind  socketname)
    (lockcout progn (cout writeln "Server: bind = " b))
    (lockcout progn (cout writeln "Server: socket-max-connections = " socket-max-connections))
    ('l set (sc listen  socket-max-connections))
    (lockcout progn (cout writeln "Server: listen = " l))
    ('a set (sc accept))
    (lockcout progn (cout writeln "Server: accept = " a))
    (nil  let ((buf ('byte-vector newobject 100)) r)
      ('r set (a  read  buf))
      (lockcout progn (cout writeln "The server received the message size "  r))) ; let buf
    (lockcout progn (cout writeln "The server sends a message to the client: Bye!"))
    ('s set (a  write "Bye!"))
    (lockcout progn (cout writeln "The server sent a " s " bytes"))
    ('c2 set (a  close))
    (lockcout progn (cout writeln "Server closed the connection with the client : " c2))
    ('c set (sc close))
    (cout writeln "Server closed : " c)
    ('u set (socketname unlink))
    (cout writeln "Server delete the file : " u)) ; let sc server
  ) ; let socketname

  First, remove the socket file, or create a new one with the same name will come. To run two processes, one server the other - client. The client will likely not be able to connect quickly, so the queries are executed with a cycle of 1 second. The server creates a socket, includes the reception of requests, the client receives, reads his message and transmits its message. Then he closes the connection with the client disconnects itself and deletes the file.
  Exceptions that occur within the client to the server will not reach, so the customer is entered in the seizure of exceptions.
  Here's how the process can occur:

unlink(My Socket)=NOENT
Server: open = nil
Client: open = nil
Server: bind = nil
Client: connect...
Server: socket-max-connections = 128
Client connect: CONNREFUSED
Server: listen = nil
Client: connect...
Server: accept = Socket(5)
Client connect: OK
The client sends a message to the server: Hi!
The client sent the 3 bytes
The server received the message size 3
The server sends a message to the client: Bye!
The server sent a 4 bytes
The client received a message size 4
Server closed the connection with the client : nil
The client closed the connection to the server : nil
Server closed : nil
Server delete the file : nil