{"size": 1583, "ext": "rktl", "max_stars_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/echo.rktl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/echo.rktl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/echo.rktl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 30.4423076923, "max_line_length": 83, "alphanum_fraction": 0.5085281112}
(require racket/tcp)

(define PORT (+ 8888 (if OPTIMIZED? 1 0)))
(define DATA "Hello there sailor\n")
(: n Integer)
(define n 10)

(: server ( -> Void))
(define (server)
  (define l (tcp-listen PORT 5 #t))
  (thread client)
  (let-values ([(in out) (tcp-accept l)]
               [(buffer) (make-string (string-length DATA))])
    (file-stream-buffer-mode out 'none)
    (let: loop : Void ([i : (U Integer EOF) (read-string! buffer in)]
                       [bytes : Integer 0])
      (if (not (eof-object? i))
          (begin
            (display buffer out)
            (loop (read-string! buffer in)
                  (+ bytes (string-length buffer))))
          (begin
            (display "server processed ")
            (display bytes)
            (display " bytes\n"))))))

(: client ( -> (U Void 'error)))
(define (client)
  (let-values ([(in out) (tcp-connect "127.0.0.1" PORT)]
               [(buffer) (make-string (string-length DATA))])
    (file-stream-buffer-mode out 'none)
    (let: loop : (U Void 'error) ([n : Integer n])
      (if (> n 0)
          (begin
            (display DATA out)
            (let ([i (read-string! buffer in)])
              (begin
                (if (equal? DATA buffer)
                    (loop (- n 1))
                    'error))))
          (close-output-port out)))))

(: main ((Vectorof String) -> Void))
(define (main args)
  (set! n
        (if (= (vector-length args) 0)
            1
            (assert (string->number (vector-ref args 0)) exact-positive-integer?)))
  (server))

(main (current-command-line-arguments))
