我正在使用这些基本的TCP测试脚本进行游戏,并想知道:“如何获取连接到服务器的客户端的IP地址?” 有什么想法吗? 我尝试在服务器端探测客户端子端口,但它不显示远程IP。 有人可以给我收集该信息的提示吗? 我知道在Rebol2中如何工作,但我不熟悉Rebol3端口模型。
您可以在客户端端口
上调用查询来获取该信息!这将返回一个带有远程IP
和远程端口
字段的对象。
以下是一个简单的示例,演示了一个简单的服务,在端口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