|
1 | 1 | #!/usr/bin/env python3 |
| 2 | +import sys |
2 | 3 | import socket |
3 | 4 | import struct |
4 | 5 | import threading |
|
7 | 8 | from time import sleep |
8 | 9 | from enum import Enum |
9 | 10 |
|
| 11 | +if sys.platform.startswith("linux"): |
| 12 | + NOSIGNAL = socket.MSG_NOSIGNAL |
| 13 | +elif sys.platform.startswith("win"): |
| 14 | + NOSIGNAL = 0 |
| 15 | + |
10 | 16 |
|
11 | 17 | class Status(Enum): |
12 | 18 | WAITING = 1 |
@@ -38,7 +44,7 @@ def __init__(self, update_callback: Callable, address: str = "127.0.0.1", port: |
38 | 44 | # Sending the client name |
39 | 45 | name = bytes(f"{name}\0", 'utf-8') |
40 | 46 | self.send_header(0, utils.PacketType.NET_PACKET_ID_SET_CLIENT_NAME, len(name)) |
41 | | - self.sock.send(name, socket.MSG_NOSIGNAL) |
| 47 | + self.sock.send(name, NOSIGNAL) |
42 | 48 |
|
43 | 49 | # Requesting the number of devices |
44 | 50 | self.send_header(0, utils.PacketType.NET_PACKET_ID_REQUEST_CONTROLLER_COUNT, 0) |
@@ -93,7 +99,7 @@ def send_header(self, device_id: int, packet_type: int, packet_size: int): |
93 | 99 | :param packet_type: a utils.PacketType |
94 | 100 | :param packet_size: the full size of the data to be send after the header |
95 | 101 | ''' |
96 | | - self.sock.send(struct.pack('ccccIII', b'O', b'R', b'G', b'B', device_id, packet_type, packet_size), socket.MSG_NOSIGNAL) |
| 102 | + self.sock.send(struct.pack('ccccIII', b'O', b'R', b'G', b'B', device_id, packet_type, packet_size), NOSIGNAL) |
97 | 103 |
|
98 | 104 | def timeout(self): |
99 | 105 | while self.state == Status.WAITING: |
|
0 commit comments