jsocket 1.9.1__py3-none-any.whl → 1.9.2__py3-none-any.whl
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.
- jsocket/jsocket_base.py +12 -8
- jsocket/tserver.py +3 -4
- {jsocket-1.9.1.dist-info → jsocket-1.9.2.dist-info}/METADATA +1 -4
- jsocket-1.9.2.dist-info/RECORD +8 -0
- {jsocket-1.9.1.dist-info → jsocket-1.9.2.dist-info}/WHEEL +1 -1
- jsocket-1.9.1.dist-info/RECORD +0 -8
- {jsocket-1.9.1.dist-info → jsocket-1.9.2.dist-info}/LICENSE +0 -0
- {jsocket-1.9.1.dist-info → jsocket-1.9.2.dist-info}/top_level.txt +0 -0
jsocket/jsocket_base.py
CHANGED
|
@@ -31,10 +31,10 @@ import time
|
|
|
31
31
|
logger = logging.getLogger("jsocket")
|
|
32
32
|
|
|
33
33
|
class JsonSocket(object):
|
|
34
|
-
def __init__(self, address='127.0.0.1', port=5489):
|
|
34
|
+
def __init__(self, address='127.0.0.1', port=5489, timeout=2.0):
|
|
35
35
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
36
36
|
self.conn = self.socket
|
|
37
|
-
self._timeout =
|
|
37
|
+
self._timeout = timeout
|
|
38
38
|
self._address = address
|
|
39
39
|
self._port = port
|
|
40
40
|
|
|
@@ -74,17 +74,21 @@ class JsonSocket(object):
|
|
|
74
74
|
return json.loads(str(msg[0],'ascii'))
|
|
75
75
|
|
|
76
76
|
def close(self):
|
|
77
|
+
logger.debug("closing all connections")
|
|
78
|
+
self._close_connection()
|
|
77
79
|
self._close_socket()
|
|
78
|
-
|
|
79
|
-
self._close_connection()
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
def _close_socket(self):
|
|
82
82
|
logger.debug("closing main socket")
|
|
83
|
-
self.socket.
|
|
83
|
+
if self.socket.fileno() != -1:
|
|
84
|
+
self.socket.shutdown(socket.SHUT_RDWR)
|
|
85
|
+
self.socket.close()
|
|
84
86
|
|
|
85
87
|
def _close_connection(self):
|
|
86
88
|
logger.debug("closing the connection socket")
|
|
87
|
-
self.conn.
|
|
89
|
+
if self.conn.fileno() != -1:
|
|
90
|
+
self.conn.shutdown(socket.SHUT_RDWR)
|
|
91
|
+
self.conn.close()
|
|
88
92
|
|
|
89
93
|
def _get_timeout(self):
|
|
90
94
|
return self._timeout
|
|
@@ -152,7 +156,7 @@ class JsonClient(JsonSocket):
|
|
|
152
156
|
return True
|
|
153
157
|
return False
|
|
154
158
|
|
|
155
|
-
|
|
159
|
+
|
|
156
160
|
if __name__ == "__main__":
|
|
157
161
|
""" basic json echo server """
|
|
158
162
|
import threading
|
jsocket/tserver.py
CHANGED
|
@@ -72,7 +72,7 @@ class ThreadedServer(threading.Thread, jsocket_base.JsonServer):
|
|
|
72
72
|
logger.exception(e)
|
|
73
73
|
self._close_connection()
|
|
74
74
|
break
|
|
75
|
-
self.
|
|
75
|
+
self._close_socket()
|
|
76
76
|
|
|
77
77
|
def start(self):
|
|
78
78
|
""" Starts the threaded server.
|
|
@@ -124,11 +124,10 @@ class ServerFactoryThread(threading.Thread, jsocket_base.JsonSocket):
|
|
|
124
124
|
logger.debug("socket.timeout: %s" % e)
|
|
125
125
|
continue
|
|
126
126
|
except Exception as e:
|
|
127
|
-
logger.info("client connection broken,
|
|
128
|
-
self._close_connection()
|
|
127
|
+
logger.info("client connection broken, exit and close connection socket")
|
|
129
128
|
self._isAlive = False
|
|
130
129
|
break
|
|
131
|
-
self.
|
|
130
|
+
self._close_connection()
|
|
132
131
|
|
|
133
132
|
def start(self):
|
|
134
133
|
""" Starts the factory thread.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: jsocket
|
|
3
|
-
Version: 1.9.
|
|
3
|
+
Version: 1.9.2
|
|
4
4
|
Summary: Python JSON Server & Client
|
|
5
5
|
Home-page: https://cpiekarski.com/2012/01/25/python-json-client-server-redux/
|
|
6
6
|
Author: Christopher Piekarski
|
|
@@ -9,7 +9,6 @@ Maintainer: Christopher Piekarski
|
|
|
9
9
|
Maintainer-email: chris@cpiekarski.com
|
|
10
10
|
License: OSI Approved Apache Software License
|
|
11
11
|
Keywords: json,socket,server,client
|
|
12
|
-
Platform: UNKNOWN
|
|
13
12
|
Classifier: Intended Audience :: Developers
|
|
14
13
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -23,5 +22,3 @@ Provides: jsocket
|
|
|
23
22
|
Requires-Python: >=3.9
|
|
24
23
|
License-File: LICENSE
|
|
25
24
|
|
|
26
|
-
UNKNOWN
|
|
27
|
-
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
jsocket/__init__.py,sha256=wDphi2h6wD6vC-DYa4mOu9qqefhOuLAdMp47YTcm0mM,2555
|
|
2
|
+
jsocket/jsocket_base.py,sha256=yUF0OYT8PcrxCqABEB9SaIR7aqYHd9_m1GgaoqlIEn4,5470
|
|
3
|
+
jsocket/tserver.py,sha256=pr9xNWdc3UU_9F1AQKBObCoubCEexZOceHobvZmaXa4,5770
|
|
4
|
+
jsocket-1.9.2.dist-info/LICENSE,sha256=r9OGvUawVBQpodY7BwMPTYja9PZebyIOvfw9_xhtMYc,828
|
|
5
|
+
jsocket-1.9.2.dist-info/METADATA,sha256=oIohjMr9i5-g5tH6UfMtb-loH5PqtEtKWRx-9-2zz5Q,956
|
|
6
|
+
jsocket-1.9.2.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
|
|
7
|
+
jsocket-1.9.2.dist-info/top_level.txt,sha256=QqfmeUi7avy9cdcsVVvG68CP-4mfg_P6E7OuBuNEcN4,8
|
|
8
|
+
jsocket-1.9.2.dist-info/RECORD,,
|
jsocket-1.9.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
jsocket/__init__.py,sha256=wDphi2h6wD6vC-DYa4mOu9qqefhOuLAdMp47YTcm0mM,2555
|
|
2
|
-
jsocket/jsocket_base.py,sha256=SCbgwOfMFEd5kyTQ8QV7u-0Pu9VEi3i0e_2A0-K7pG4,5304
|
|
3
|
-
jsocket/tserver.py,sha256=_3cExGx2eCUverSLKkTu96BsyJkZNNknMkpG9aQoyZM,5761
|
|
4
|
-
jsocket-1.9.1.dist-info/LICENSE,sha256=r9OGvUawVBQpodY7BwMPTYja9PZebyIOvfw9_xhtMYc,828
|
|
5
|
-
jsocket-1.9.1.dist-info/METADATA,sha256=sznHam1Ew4EqZi9XxHm-VBtzAq2H6m12iIjlQ32c9qs,983
|
|
6
|
-
jsocket-1.9.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
7
|
-
jsocket-1.9.1.dist-info/top_level.txt,sha256=QqfmeUi7avy9cdcsVVvG68CP-4mfg_P6E7OuBuNEcN4,8
|
|
8
|
-
jsocket-1.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|