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 /feasibility_analysis/tcpevents | |
parent | 4890b61f08698a84e261f162dc2acd404bcc6b6b (diff) | |
parent | 44c715c55c239495da8f780276866c0041f04139 (diff) |
Merge pull request #1 from oplS17projects/mango0.2
Mango
Diffstat (limited to 'feasibility_analysis/tcpevents')
-rw-r--r-- | feasibility_analysis/tcpevents/README.md | 1 | ||||
-rw-r--r-- | feasibility_analysis/tcpevents/server.rkt | 39 |
2 files changed, 0 insertions, 40 deletions
diff --git a/feasibility_analysis/tcpevents/README.md b/feasibility_analysis/tcpevents/README.md deleted file mode 100644 index 7c3ec21..0000000 --- a/feasibility_analysis/tcpevents/README.md +++ /dev/null @@ -1 +0,0 @@ -TCP communication racket concepts of events. For more see the racket guide. diff --git a/feasibility_analysis/tcpevents/server.rkt b/feasibility_analysis/tcpevents/server.rkt deleted file mode 100644 index 4313bda..0000000 --- a/feasibility_analysis/tcpevents/server.rkt +++ /dev/null @@ -1,39 +0,0 @@ -#lang racket - -(define (serve in-port out-port) - (let loop [] - (define evt (sync/timeout 2 - (read-line-evt in-port 'any) - (thread-receive-evt))) - (cond - [(not evt) - (displayln "Timed out, exiting") - (tcp-abandon-port in-port) - (tcp-abandon-port out-port)] - [(string? evt) - (fprintf out-port "~a~n" evt) - (flush-output out-port) - (loop)] - [else - (printf "Received a message in mailbox: ~a~n" - (thread-receive)) - (loop)]))) - -(define port-num 4321) -(define (start-server) - (define listener (tcp-listen port-num)) - (thread - (lambda () - (define-values [in-port out-port] (tcp-accept listener)) - (serve in-port out-port)))) - -(start-server) - -(define client-thread - (thread - (lambda () - (define-values [in-port out-port] (tcp-connect "localhost" port-num)) - (display "first\nsecond\nthird\n" out-port) - (flush-output out-port) - ; copy-port will block until EOF is read from in-port - (copy-port in-port (current-output-port))))) |