aboutsummaryrefslogtreecommitdiff
path: root/feasibility_analysis/tcpvanilla/server.rkt
diff options
context:
space:
mode:
authoriskm <iskm@users.noreply.github.com>2017-04-09 22:49:46 -0400
committerGitHub <noreply@github.com>2017-04-09 22:49:46 -0400
commit385c4f4664ae8157e62f118f15d4c670a4c1356b (patch)
treedcb37e29867a6294e8a321ea535e6e9ecd03c296 /feasibility_analysis/tcpvanilla/server.rkt
parent4890b61f08698a84e261f162dc2acd404bcc6b6b (diff)
parent44c715c55c239495da8f780276866c0041f04139 (diff)
Merge pull request #1 from oplS17projects/mango0.2
Mango
Diffstat (limited to 'feasibility_analysis/tcpvanilla/server.rkt')
-rw-r--r--feasibility_analysis/tcpvanilla/server.rkt58
1 files changed, 0 insertions, 58 deletions
diff --git a/feasibility_analysis/tcpvanilla/server.rkt b/feasibility_analysis/tcpvanilla/server.rkt
deleted file mode 100644
index bf72aff..0000000
--- a/feasibility_analysis/tcpvanilla/server.rkt
+++ /dev/null
@@ -1,58 +0,0 @@
-#lang racket
-
-;; Both `server' and `accept-and-handle' change
-;; to use a custodian.
-;; To start server
-;; (define stop (serve 8080))
-;; use your web browser to connect localhost:8080 greeted with "hello world"
-;; (stop) to close the server
-
-(define (serve port-no)
- (define main-cust (make-custodian))
- (parameterize ([current-custodian main-cust])
- (define listener (tcp-listen port-no 5 #t))
- (define (loop)
- (accept-and-handle listener)
- (loop))
- (thread loop))
- (lambda ()
- (displayln "\nGoodbye, shutting down all services\n")
- (custodian-shutdown-all main-cust)))
-
-(define (accept-and-handle listener)
- (define cust (make-custodian))
- (parameterize ([current-custodian cust])
- (define-values (in out) (tcp-accept listener))
- (thread (lambda ()
- (handle in out) ;; this handles connection with that specific client
- (close-input-port in)
- (close-output-port out))))
- ;; Watcher thread:
- (thread (lambda ()
- (sleep 120)
- (custodian-shutdown-all cust))))
-
-(define (handle in out)
- ; (server-loop in out)
- (sleep 5) ;; wait 5 seconds to guarantee client has already send message
- (define echo (read-line in)) ;; bind message to echo
- (displayln (string-append echo "\n"))
- ; echo back the message, appending echo
- ; could regex match the input to extract the name
- (writeln "Admin: Hello there" out) ;; append "echo " to echo and send back
- (flush-output out)
-)
-
-(define input-prompt "Hermes: ")
-
-(define (server-loop in out)
- (define echo (read-line in))
- (displayln echo)
- (display ">>> ")
-
- (define input (read))
- (writeln (string-append "Admin: " input) out)
- (flush-output out)
- ; (sleep 10)
- (server-loop in out))
-