TcpClient

Last edit

Summary: CategoryExtensions

Added:

> ----
> CategoryExtensions


Lisp:tcp-client.el

The purpose of this library is to provide a network interface to ease the creation of network related script.

This library is dependending on record-type.el (RecordType)

Here is an example of how to use it:

  (defun sample-error-report(buffer server port error)
    (save-excursion
     (set-buffer buffer)
      (insert (format "[error] %s:%i -- %s\n" server port error))))
  
  (defun sample-connection-report(buffer server port)
    (save-excursion
      (set-buffer buffer)
      (insert (format "[connect] %s:%i -- Connection established\n" server port))))
  
  (defun sample-abort-report(buffer server port)
    (save-excursion
      (set-buffer buffer)
      (insert (format "[error] %s:%i -- Abort connection\n" server port))))
  
  (defun sample-sentinel-report(process event)
    (save-excursion
      (set-buffer (process-buffer process))
      (insert (format "[event] Process: %s had the event -- %s" process event))))
  
  (defun sample-filter-report(process message)
    (save-excursion
      (set-buffer (process-buffer process))
      (insert (format "[got] %s" message))))
  
  
  (tcp-connect "*ok*" 
  	     (make-new-tcp-connection :server "127.0.0.1" :port 1000)
  	     (make-new-tcp-hooks 
  			      :connection-failed-handler 'sample-error-report
  			      :connection-established-handler 'sample-connection-report
  			      :connection-abort-handler 'sample-abort-report))
  
  (tcp-connect "*test*" 
  	     (make-new-tcp-connection :server "127.0.0.1" :port 2000)
  	     (make-new-tcp-hooks 
  			      :connection-failed-handler 'sample-error-report
  			      :connection-established-handler 'sample-connection-report
  			      :connection-abort-handler 'sample-abort-report
  			      :sentinel-handler 'sample-sentinel-report
  			      :filter-handler 'sample-filter-report))

CategoryExtensions