current position:Home>AttributeError: ‘socket‘ object has no attribute ‘ioctl‘ python linux

AttributeError: ‘socket‘ object has no attribute ‘ioctl‘ python linux

2022-02-02 13:43:55 caohh163

Beginners python Refer to the common code settings on the Internet TCP The heart of :

    def __init__(self, IP="", Port=5555):

        """ Initialize object """

        self.code_mode = "utf-8"    # Transceiving data coding / Decoding format

        self.IP = IP

        self.Port = Port

        self.my_socket =socket(AF_INET, SOCK_STREAM)   # establish socket



Run time error :

AttributeError: 'socket' object has no attribute 'ioctl'

Find out vsc There are no exceptions in the , Rewriting code can also automatically complement , explain SOCKET There is this function . I checked that there is no relevant wrong information on the Internet , This may be a personal lack of TCP Common sense . open python Of socket.ioctl Definition , That's confirmed . The definition is as follows :

if sys.platform == "win32":

        def ioctl(self, __control: int, __option: int | tuple[int, int, int] | bool) -> None: ...

Sum up : I am here win7 In the use vs Write code , Upload to linux function , and ioctl Only in window It works .

linux The following should read



        self.my_socket.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 10)

        self.my_socket.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3)

        self.my_socket.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5)

copyright notice
author[caohh163],Please bring the original link to reprint, thank you.

Random recommended