gpt4 book ai didi

sockets - 如何写入双工流?

转载 作者:行者123 更新时间:2023-12-03 11:59:49 25 4
gpt4 key购买 nike

假设我有一个 super 简单套接字服务器,它在localhost的端口上接受连接:

: server-new ( port -- stream ) f swap <inet4> utf8 <server> accept drop ;

我可以像这样使用它:
IN: scratchpad 1204 server-new 

哪个等待连接。在终端中:
$ curl localhost:1204
_

然后等待服务器回复。 server-new在堆栈上保留一个 duplex-stream
T{ duplex-stream
{ in
T{ decoder
{ stream
T{ input-port
{ handle T{ fd { fd 36 } } }
{ buffer
T{ buffer
{ size 65536 }
{ ptr ALIEN: 1a44530 }
}
}
}
}
{ code utf8 }
}
}
{ out
T{ encoder
{ stream
T{ output-port
{ handle T{ fd { fd 36 } } }
{ buffer
T{ buffer
{ size 65536 }
{ ptr ALIEN: 1d42b30 }
}
}
}
}
{ code utf8 }
}
}
}

我想给客户端写一个字符串。我该怎么做呢?

似乎 with-stream或其他某种方式可以解决问题,但这只是消耗了流对象,而没有任何内容写入我的 curl客户端。

最佳答案

它可能在某处缺少冲洗:

[ "hello from Factor" print flush ] with-stream

还要注意,报价结束时 with-stream将关闭流。如果要使其保持打开状态,请改为使用 with-stream*

关于sockets - 如何写入双工流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36511260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com