Skip to main content
 首页 » 编程设计

python之在python中断开UDP套接字

2025年05月04日9softidea

我需要在 python 中“断开”一个 UDP 套接字(而不是关闭它!)。

是否有可能做等同于:

int disconnect_udp_sock(int fd) 
{ 
    struct sockaddr_in sin;         
 
    memset((char *)&sin, 0, sizeof(sin)); 
    sin.sin_family = AF_UNSPEC; 
    return (connect(fd, (struct sockaddr *)&sin, sizeof(sin))); 
} 

取自here在 python 中没有接口(interface)函数?

请您参考如下方法:

查看 Python 2.7 源代码中的 socketmodule.c,似乎不可能。您确实需要定义并调用上面的 C 函数。