如何从raku中的IO :: socket :: async获得一行?
因此,我有:
my $conn = await IO::Socket::Async.connect('127.0.0.1', 12340);
$conn.print: "GET /rest HTTP/1.1\r\n\r\n";
如何仅接收服务器的第一行?
我可以在时使用并在其中使用一些逻辑,但是有一种简单的方法,对吗?
So, I have this:
my $conn = await IO::Socket::Async.connect('127.0.0.1', 12340);
$conn.print: "GET /rest HTTP/1.1\r\n\r\n";
How to receive just the first line from the server ?
I could use whenever
and put some logic in it, but there's a simpler way, right ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您真的只想要第一行,并且不在乎其余的响应,那么您可以做到这一点:
也就是说,获取代表响应流的
supply
,是否将其拆分为行(这导致了行的供应
),并采用到达的第一行。一行以外收到的任何数据都将被丢弃。io :: socket :: async
在提供数据数据包时起作用。它没有提供面向线路的接口;如果协议确实如此简单,就像逐条阅读,那么每当$ conn.supply.lines -lines-> $ line {} 将执行此操作(并且处理行为正确分配的行)。If you really only want the first line, and don't care about the rest of the response, then you can do this:
That is, get the
Supply
representing the response stream, have it split into lines (which results in aSupply
of lines), and take the first line that arrives. Any data received beyond the first line will be discarded.IO::Socket::Async
works in terms of providing packets of data as they arrive. It doesn't get into providing a line-oriented interface; if a protocol really is so simple as reading line by line, then areact whenever $conn.Supply.lines -> $line { }
will do it (and handles lines split over packets correctly).