diff options
author | iskm <iskm@users.noreply.github.com> | 2017-04-09 22:49:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-09 22:49:46 -0400 |
commit | 385c4f4664ae8157e62f118f15d4c670a4c1356b (patch) | |
tree | dcb37e29867a6294e8a321ea535e6e9ecd03c296 /tests/tcpvanilla/tcptalk.rkt | |
parent | 4890b61f08698a84e261f162dc2acd404bcc6b6b (diff) | |
parent | 44c715c55c239495da8f780276866c0041f04139 (diff) |
Merge pull request #1 from oplS17projects/mango0.2
Mango
Diffstat (limited to 'tests/tcpvanilla/tcptalk.rkt')
-rw-r--r-- | tests/tcpvanilla/tcptalk.rkt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/tcpvanilla/tcptalk.rkt b/tests/tcpvanilla/tcptalk.rkt new file mode 100644 index 0000000..d069851 --- /dev/null +++ b/tests/tcpvanilla/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 |