simple-socket-client 1.3__tar.gz → 1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simple-socket-client-1.3/simple_socket_client.egg-info → simple-socket-client-1.5}/PKG-INFO +3 -3
- {simple-socket-client-1.3 → simple-socket-client-1.5}/README.md +2 -2
- {simple-socket-client-1.3 → simple-socket-client-1.5}/setup.py +1 -1
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client/__init__.py +41 -28
- {simple-socket-client-1.3 → simple-socket-client-1.5/simple_socket_client.egg-info}/PKG-INFO +3 -3
- {simple-socket-client-1.3 → simple-socket-client-1.5}/LICENSE.md +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/MANIFEST.in +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/requirements.txt +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/setup.cfg +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/SOURCES.txt +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/dependency_links.txt +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/not-zip-safe +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/requires.txt +0 -0
- {simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/top_level.txt +0 -0
{simple-socket-client-1.3/simple_socket_client.egg-info → simple-socket-client-1.5}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: simple-socket-client
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5
|
|
4
4
|
Summary: Simple TCP socket client
|
|
5
5
|
Home-page: https://github.com/webtoucher/simple-socket-client
|
|
6
6
|
Author: Alexey Kuznetsov
|
|
@@ -35,7 +35,7 @@ $ pip install simple-socket-client
|
|
|
35
35
|
Or you can add it as dependency in requirements.txt file of your python application:
|
|
36
36
|
|
|
37
37
|
```
|
|
38
|
-
simple-socket-client~=1.
|
|
38
|
+
simple-socket-client~=1.5
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Usage
|
|
@@ -44,7 +44,7 @@ simple-socket-client~=1.3
|
|
|
44
44
|
from simple_socket_client import SimpleSocketClient
|
|
45
45
|
|
|
46
46
|
client = SimpleSocketClient('192.168.0.2', 6666)
|
|
47
|
-
client.connect()
|
|
47
|
+
client.connect(timeout=10)
|
|
48
48
|
|
|
49
49
|
client.send('Test'.encode()) # if you don't need an answer
|
|
50
50
|
answer = client.ask('Hi!'.encode())
|
|
@@ -16,7 +16,7 @@ $ pip install simple-socket-client
|
|
|
16
16
|
Or you can add it as dependency in requirements.txt file of your python application:
|
|
17
17
|
|
|
18
18
|
```
|
|
19
|
-
simple-socket-client~=1.
|
|
19
|
+
simple-socket-client~=1.5
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
@@ -25,7 +25,7 @@ simple-socket-client~=1.3
|
|
|
25
25
|
from simple_socket_client import SimpleSocketClient
|
|
26
26
|
|
|
27
27
|
client = SimpleSocketClient('192.168.0.2', 6666)
|
|
28
|
-
client.connect()
|
|
28
|
+
client.connect(timeout=10)
|
|
29
29
|
|
|
30
30
|
client.send('Test'.encode()) # if you don't need an answer
|
|
31
31
|
answer = client.ask('Hi!'.encode())
|
|
@@ -20,56 +20,69 @@ class SimpleSocketClientException(socket.error):
|
|
|
20
20
|
|
|
21
21
|
class SimpleSocketClient(EventBus):
|
|
22
22
|
def __init__(self, host: str, port: int):
|
|
23
|
+
super().__init__()
|
|
23
24
|
self.__host = host
|
|
24
25
|
self.__port = port
|
|
25
26
|
self.__socket = None
|
|
26
27
|
self.__thread = None
|
|
28
|
+
self.__thread_err = None
|
|
27
29
|
self.__outgoing_messages = None
|
|
28
30
|
self.__connected = False
|
|
29
31
|
self.__keep_answer = False
|
|
30
32
|
|
|
31
|
-
def connect(self) -> None:
|
|
32
|
-
self.
|
|
33
|
+
def connect(self, timeout=None) -> None:
|
|
34
|
+
self.__thread_err = None
|
|
35
|
+
self.__thread = Thread(target=self.__threading, args=(self, timeout))
|
|
33
36
|
self.__thread.start()
|
|
34
37
|
while not self.__connected:
|
|
35
|
-
|
|
38
|
+
if self.__thread_err:
|
|
39
|
+
raise self.__thread_err
|
|
36
40
|
|
|
37
41
|
def disconnect(self) -> None:
|
|
38
42
|
self.__connected = False
|
|
39
43
|
|
|
40
44
|
@staticmethod
|
|
41
|
-
def __threading(client):
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
client.emit('connect', (client.__host, client.__port))
|
|
50
|
-
while client.__connected:
|
|
45
|
+
def __threading(client, timeout):
|
|
46
|
+
try:
|
|
47
|
+
client.__incoming_messages = queue.Queue()
|
|
48
|
+
client.__outgoing_messages = queue.Queue()
|
|
49
|
+
client.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
50
|
+
if client.__socket.fileno() < 0:
|
|
51
|
+
raise SimpleSocketClientException('Problem with creating sockets')
|
|
52
|
+
client.__socket.settimeout(timeout)
|
|
51
53
|
try:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
client.__socket.connect((client.__host, client.__port))
|
|
55
|
+
except TimeoutError as err:
|
|
56
|
+
raise SimpleSocketClientException('Connection timed out') from err
|
|
57
|
+
client.__socket.settimeout(None)
|
|
58
|
+
client.__connected = True
|
|
59
|
+
client.emit('connect', (client.__host, client.__port))
|
|
60
|
+
while client.__connected:
|
|
61
|
+
try:
|
|
62
|
+
if client.__socket.fileno() > 0:
|
|
63
|
+
message = client.__outgoing_messages.get_nowait()
|
|
64
|
+
else:
|
|
65
|
+
client.disconnect()
|
|
66
|
+
continue
|
|
67
|
+
except queue.Empty:
|
|
56
68
|
continue
|
|
57
|
-
except queue.Empty:
|
|
58
|
-
continue
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
try:
|
|
71
|
+
if message:
|
|
72
|
+
client.__socket.sendall(message)
|
|
73
|
+
if client.__keep_answer:
|
|
74
|
+
client.__receive_message()
|
|
75
|
+
except ConnectionResetError:
|
|
76
|
+
client.disconnect()
|
|
77
|
+
except SimpleSocketClientException as err:
|
|
78
|
+
client.__thread_err = err
|
|
67
79
|
|
|
68
80
|
client.emit('disconnect', (client.__host, client.__port))
|
|
69
81
|
client.__incoming_messages = None
|
|
70
82
|
client.__outgoing_messages = None
|
|
71
|
-
client.__socket
|
|
72
|
-
|
|
83
|
+
if client.__socket:
|
|
84
|
+
client.__socket.close()
|
|
85
|
+
client.__socket = None
|
|
73
86
|
|
|
74
87
|
def send(self, message: bytes) -> None:
|
|
75
88
|
if not self.__connected:
|
{simple-socket-client-1.3 → simple-socket-client-1.5/simple_socket_client.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: simple-socket-client
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5
|
|
4
4
|
Summary: Simple TCP socket client
|
|
5
5
|
Home-page: https://github.com/webtoucher/simple-socket-client
|
|
6
6
|
Author: Alexey Kuznetsov
|
|
@@ -35,7 +35,7 @@ $ pip install simple-socket-client
|
|
|
35
35
|
Or you can add it as dependency in requirements.txt file of your python application:
|
|
36
36
|
|
|
37
37
|
```
|
|
38
|
-
simple-socket-client~=1.
|
|
38
|
+
simple-socket-client~=1.5
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
## Usage
|
|
@@ -44,7 +44,7 @@ simple-socket-client~=1.3
|
|
|
44
44
|
from simple_socket_client import SimpleSocketClient
|
|
45
45
|
|
|
46
46
|
client = SimpleSocketClient('192.168.0.2', 6666)
|
|
47
|
-
client.connect()
|
|
47
|
+
client.connect(timeout=10)
|
|
48
48
|
|
|
49
49
|
client.send('Test'.encode()) # if you don't need an answer
|
|
50
50
|
answer = client.ask('Hi!'.encode())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/requires.txt
RENAMED
|
File without changes
|
{simple-socket-client-1.3 → simple-socket-client-1.5}/simple_socket_client.egg-info/top_level.txt
RENAMED
|
File without changes
|