How do I get the remote IP-Address of clients connecting to a Rebol3 based server?

StackOverflow https://stackoverflow.com/questions/18398111

  •  26-06-2022
  •  | 
  •  

Pergunta

I'm playing with these basic TCP test scripts and would like to know: "How to get the IP-Address of clients connecting to the server?"

Any ideas? I tried to probe a client subport at the server-side, but it doesn't show the remote-ip.

Can someone give me hints on gathering that information. I know how it works within Rebol2, but I'm not familiar with the Rebol3 port model.

Foi útil?

Solução

You can obtain that information by calling QUERY on the client port!, which will return an object with remote-ip and remote-port fields.

Here's a simple example illustrating this, with a simple service that listens for connections on port 9090 and prints the address of clients connecting to that service:

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

Outras dicas

The system/standard/net-info object includes two values - local-ip and remote-ip. I'm not sure whether that they get set though.

Give system/standard/net-info/remote-ip a try and if it contains none, I would suggest submitting a bug report.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top