我正在寫一個需要進程間通信的程序。球拍中的子過程
我的代碼:
#lang racket
(define-values (sp o i e) (subprocess #f #f #f "c://player1.exe"))
(define count 10)
(for ([c (in-naturals)])
(cond
[(equal? count 0) (error "Province is empty!") ]
[else
(write "server" i)
(set! count (sub1 count))
(flush-output i)
(display (read o))]))
和player1.exe代碼:
#lang racket
(define (interact notification)
(cond
[(eq? notification "server") (write "true" (current-output-port))]
[else (write "false" (current-output-port))]))
(for ([c (in-naturals)])
(interact (read (current-input-port)))
(write "player" (current-output-port))
(sleep 0.1)
flush-output (current-output-port))
我得到的輸出,如果我沒有循環運行。只有玩家發送消息時,我也會得到輸出。但是,隨着服務器和播放器發送消息,程序被掛起。 你認爲問題是什麼?
我重新縮進了代碼,使其更清晰一些。 – dyoo 2012-02-11 22:38:37