Guest User

Untitled

a guest
Jan 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.23 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;;TCP
  4.  
  5. ;;print-from-port : port -> void
  6. ;;prints out lines from the port until there are no more lines to print.
  7. (define (print-from-port port)
  8.   (if (char-ready? port)
  9.       (let ([nextchar (read-char port)])
  10.         (printf (if (char=? #\~ nextchar)
  11.                     "~~"
  12.                     (string nextchar)))
  13.         (print-from-port port))
  14.       (printf "~n")))
  15.  
  16. ;;send-to-port : port -> void
  17. ;;sends direct input from the user to the port.
  18. (define (send-to-port port)
  19.   (let ([input (read-line)])
  20.     (if (not (string=? input "n"))
  21.         (begin (display (string-append input "\r\n") port)
  22.                (flush-output port)
  23.                (printf "Sending ~a~n" input))
  24.         (printf "Not sending anything.~n"))))
  25.  
  26. ;;irc-connect : string number (port port -> void) -> void
  27. ;;connects to an IRC network, and begins running the provided irc handler.
  28. (define (irc-connect server port handler)
  29.          (call-with-values (lambda () (tcp-connect server port))
  30.                   (λ arguments (handler (first arguments) (second arguments)))))
  31.  
  32. (define (irc-handle in out)
  33.   (print-from-port in)
  34.   (send-to-port out)
  35.   (irc-handle in out))
  36.  
  37.  
  38. ;;GUI
  39.  
  40.  
  41.  
  42. (irc-connect "irc.foonetic.net" 6667 irc-handle)
Add Comment
Please, Sign In to add comment