For beginners of python, refer to the common codes on the Internet to set the heartbeat of TCP:
def __ init__ (self, IP=”127.0.0.1″, Port=5555):
“” “initialize object” “”
self.code_mode = “utf-8” # Transceiving data encoding/decoding format
self.IP = IP
self.Port = Port
self.my_socket =socket(AF_INET, SOCK_STREAM) # Create socket
self.my_socket.setsockopt(SOL_SOCKET,SO_KEEPALIVE,True)
self.my_socket.ioctl(SIO_KEEPALIVE_VALS,(1,10000,1000))
Run error:
AttributeError: ‘socket’ object has no attribute ‘ioctl’
It is found that there are no exceptions marked in VSC, and the rewritten code can be automatically supplemented, indicating that socket has this function. I checked that there is no relevant wrong information on the Internet, which may be due to my lack of TCP related common sense. This is confirmed by opening the socket.ioctl definition of Python. The definition is as follows:
if sys.platform == “win32”:
def ioctl(self, __control: int, __option: int | tuple[int, int, int] | bool) -> None: …
To sum up: I write code with vs in win7 and upload it to Linux for operation, while IOCTL is only valid in window.
Under Linux, it should be changed to
self.my_socket.setsockopt(SOL_SOCKET,SO_KEEPALIVE,True)
# self.my_socket.ioctl(SIO_KEEPALIVE_VALS,(1,10000,1000))
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)
Read More:
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’
- Python Openyxl Error: AttributeError: ‘int‘ object has no attribute ‘upper‘ [How to Solve]
- [Solved] Python Keras Error: AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘
- [Solved] python Error: AttributeError: ‘NoneType‘ object has no attribute ‘split‘
- [Solved] Python Selenium Error: AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_xpath‘
- Python writes DICOM file (attributeerror: ‘filemetadataset’ object has no attribute ‘transfersyntax uid’ solution)
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- AttributeError: DatetimeProperties object has no attribute
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘