gforth是否包含网络套接字功能? [英] Does gforth contain network socket capability?

查看:153
本文介绍了gforth是否包含网络套接字功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,在学习语言时,我会编写某种服务器。 gforth 是否有能力使用网络套接字?

Often, when learning a language I'll write a server of some sort. Does gforth have the capability to use network sockets?

我在手册。

推荐答案

虽然我没有看到任何关于它的文档,但是有一个 socket.fs 绑定到libc。

Though I don't see any documentation about it, there is a socket.fs which binds to libc.

  • You can find some examples of FORTH that use sockets.fs on Rosetta Code, specifically the ECHO server example

GNU FD L,从由IanOsgood 提交

include unix/socket.fs

128 constant size

: (echo) ( sock buf -- sock buf )
  begin
    cr ." waiting..."
    2dup 2dup size read-socket nip
    dup 0>
  while
    ."  got: " 2dup type
    rot write-socket
  repeat
  drop drop drop ;

create buf size allot

: echo-server ( port -- )
  cr ." Listening on " dup .
  create-server
  dup 4 listen
  begin
    dup accept-socket
    cr ." Connection!"
    buf ['] (echo) catch
    cr ." Disconnected (" . ." )"
    drop close-socket
  again ;

12321 echo-server

但是,ymmv

nc localhost 12321
PING
PING
PONG
PONG

没有Keepalive,因此您可以从逻辑上断开连接。

There are no Keepalives so you'll logically get disconnects from that.

这篇关于gforth是否包含网络套接字功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆