gpt4 book ai didi

sockets - 在 Erlang 中确定传入 TCP/IP 连接的 IP 地址和端口

转载 作者:可可西里 更新时间:2023-11-01 02:30:37 25 4
gpt4 key购买 nike

我想获取传入 TCP/IP 连接的 IP 地址和端口号。不幸的是 gen_tcpacceptrecv 函数只返回一个套接字,而 gen_udprecv 函数还返回地址信息。有没有一种直接的方法来收集属于 Erlang 中的套接字的地址信息?

最佳答案

您需要 inet/peername 1。来自Erlang inet docs :

peername(Socket) -> {ok, {Address, Port}} | {error, posix()}

Types:

Socket = socket() Address = ip_address() Port = int()

Returns the address and port for the other end of a connection.

关于sockets - 在 Erlang 中确定传入 TCP/IP 连接的 IP 地址和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1240312/

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