5

我正在使用这些基本的 TCP 测试脚本并想知道:“如何获取连接到服务器的客户端的 IP 地址?”

有任何想法吗?我试图在服务器端探测客户端子端口,但它没有显示远程 IP。

有人可以给我关于收集这些信息的提示吗?我知道它在 Rebol2 中是如何工作的,但我不熟悉 Rebol3 端口模型。

4

2 回答 2

4

您可以通过在客户端上调用 QUERY 来获取该信息port!,这将返回一个带有remote-ipremote-port字段的对象。

这里有一个简单的例子来说明这一点,一个简单的服务监听端口 9090 上的连接并打印连接到该服务的客户端的地址:

rebol []

awake-server: func [event /local client info] [
    if event/type = 'accept [
        client: first event/port
        info: query client
        print ajoin ["Client connected: " info/remote-ip ":" info/remote-port]
        close client
    ]
]

serve: func [endpoint /local listen-port] [
    listen-port: open endpoint
    listen-port/awake: :awake-server
    wait listen-port
]

serve tcp://:9090
于 2013-10-02T00:57:03.920 回答
1

system/standard/net-info 对象包括两个值 - local-ip 和 remote-ip。我不确定他们是否已经设置好了。

试试 system/standard/net-info/remote-ip,如果没有,我建议提交错误报告。

于 2013-08-25T23:34:50.773 回答