首页 > 解决方案 > Ocaml / 异步套接字问题

问题描述

我对 OCaml 很陌生,我正在使用 Async/Core 开发一个小型 TCP 客户端实用程序。

使用打开连接

Tcp.with_connection (Tcp.Where_to_connect.of_host_and_port { host = "localhost"; port = myPort })

我需要能够接受键盘输入,以及从套接字读取输入。为此,我使用 Deferred.any。

调用Reader.read reader buf套接字会导致 `Eof,这没关系,但是当递归调用方法(包含 Deferred.any 代码)时,我得到一个异常:

“unhandled exception in Async scheduler”
(“unhandled exception”
((monitor.ml.Error
(“can not read from reader” (reason “in use”)
.....

Reader.is_closed在阅读器上返回 false。如果没有这个例外,我怎样才能递归地“监视”套接字?

迈克尔

标签: asynchronousocaml

解决方案


推荐阅读