Disconnect UDP socket in python?

試著忘記壹切 提交于 2021-02-18 18:13:38

问题


I need to 'disconnect' a UDP socket in python(and not close it!).

Is it possible to do the equivalent of:

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)));
}

taken from here in python without interfacing the function?


回答1:


Looking at socketmodule.c in the Python 2.7 sources, it doesn't seem possible. You really need to define and call the C function above.



来源:https://stackoverflow.com/questions/16828171/disconnect-udp-socket-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!