diff options
author | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-03-29 23:47:48 -0400 |
---|---|---|
committer | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-03-29 23:47:48 -0400 |
commit | 847a5d2b4307113c9c198c9d9d1958f2074a500d (patch) | |
tree | 5940a4b17a0f3920f40ca3a56365bf370c432a75 /tcptalk.rkt | |
parent | 57de71567c9175861685bc055c8dd87fae0bed41 (diff) |
Added previous work on the libraries i used from FP1, and FP2 with more addons
Diffstat (limited to 'tcptalk.rkt')
-rw-r--r-- | tcptalk.rkt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tcptalk.rkt b/tcptalk.rkt new file mode 100644 index 0000000..d069851 --- /dev/null +++ b/tcptalk.rkt @@ -0,0 +1,30 @@ +#lang racket + +(define listener (tcp-listen 8083 5 #t)) ;; listener to service connection requests +;; client attempts to connect. Receives an input and output port +(define-values (client-in client-out) (tcp-connect "localhost" 8083)) +;; server accepts the connection request. Also gets a pair of ports +(define-values (server-in server-out) (tcp-accept listener)) + +;; client sends identifying message +(display (string-append "Client:My name is " "Ibrahim" "\n") + client-out) +(flush-output client-out) ;; must flush as ports are buffered in racket + +;; server receives and reads it +;; cooler if on separate racket instances +(read-line server-in) ;; --> "Client:My name is #hostname. +;; server replies +(display (string-append "Server:Hi " "Ibrahim" "\n") server-out) +(flush-output server-out) ;; flush flush + +;; client displays server message +(read-line client-in) +(close-output-port server-out) +(close-output-port client-out) +(read-line client-in) ;; --> eof object #eof +(read-line server-in) ;; --> eof object #eof +(tcp-close listener) +; (custodian-shutdown-all (current-custodian)) ;; release all resources including + ;; tcp, file, custom ports + ;; application exits |