jsocket 1.8.2__tar.gz → 1.9.2__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.
- jsocket-1.9.2/LICENSE +21 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/PKG-INFO +5 -6
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket/jsocket_base.py +12 -8
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket/tserver.py +20 -15
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket.egg-info/PKG-INFO +5 -6
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket.egg-info/SOURCES.txt +1 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/setup.py +3 -3
- {jsocket-1.8.2 → jsocket-1.9.2}/README.md +0 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket/__init__.py +0 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket.egg-info/dependency_links.txt +0 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/jsocket.egg-info/top_level.txt +0 -0
- {jsocket-1.8.2 → jsocket-1.9.2}/setup.cfg +0 -0
jsocket-1.9.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
This file is part of the jsocket module.
|
|
2
|
+
Copyright (C) 2011 by
|
|
3
|
+
Christopher Piekarski <chris@cpiekarski.com>
|
|
4
|
+
|
|
5
|
+
The jsocket module is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The jsocket module is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with jsocket module. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
|
|
20
|
+
See the examples_servers.py file for several examples of how to use
|
|
21
|
+
this module.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 1
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: jsocket
|
|
3
|
-
Version: 1.
|
|
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
|
|
@@ -8,12 +8,10 @@ Author-email: chris@cpiekarski.com
|
|
|
8
8
|
Maintainer: Christopher Piekarski
|
|
9
9
|
Maintainer-email: chris@cpiekarski.com
|
|
10
10
|
License: OSI Approved Apache Software License
|
|
11
|
-
Description: UNKNOWN
|
|
12
11
|
Keywords: json,socket,server,client
|
|
13
|
-
Platform: UNKNOWN
|
|
14
12
|
Classifier: Intended Audience :: Developers
|
|
15
13
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
15
|
Classifier: Operating System :: OS Independent
|
|
18
16
|
Classifier: Development Status :: 5 - Production/Stable
|
|
19
17
|
Classifier: Topic :: System :: Networking
|
|
@@ -21,4 +19,5 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
|
21
19
|
Classifier: Topic :: System :: Distributed Computing
|
|
22
20
|
Classifier: Topic :: System :: Hardware :: Symmetric Multi-processing
|
|
23
21
|
Provides: jsocket
|
|
24
|
-
Requires-Python: >=3.
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
License-File: LICENSE
|
|
@@ -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
|
|
@@ -20,7 +20,7 @@ __copyright__= """
|
|
|
20
20
|
GNU General Public License for more details.
|
|
21
21
|
|
|
22
22
|
You should have received a copy of the GNU General Public License
|
|
23
|
-
along with tserver module.
|
|
23
|
+
along with tserver module. If not, see <http://www.gnu.org/licenses/>."""
|
|
24
24
|
__version__ = "1.0.2"
|
|
25
25
|
|
|
26
26
|
import jsocket.jsocket_base as jsocket_base
|
|
@@ -42,8 +42,8 @@ class ThreadedServer(threading.Thread, jsocket_base.JsonServer):
|
|
|
42
42
|
|
|
43
43
|
This method is called every time a JSON object is received from a client
|
|
44
44
|
|
|
45
|
-
@param obj
|
|
46
|
-
@retval
|
|
45
|
+
@param obj JSON "key: value" object received from client
|
|
46
|
+
@retval None or a response object
|
|
47
47
|
"""
|
|
48
48
|
pass
|
|
49
49
|
|
|
@@ -61,7 +61,10 @@ class ThreadedServer(threading.Thread, jsocket_base.JsonServer):
|
|
|
61
61
|
while self._isAlive:
|
|
62
62
|
try:
|
|
63
63
|
obj = self.read_obj()
|
|
64
|
-
self._process_message(obj)
|
|
64
|
+
resp_obj = self._process_message(obj)
|
|
65
|
+
if resp_obj is not None:
|
|
66
|
+
logger.debug("message has a response")
|
|
67
|
+
self.send_obj(resp_obj)
|
|
65
68
|
except socket.timeout as e:
|
|
66
69
|
logger.debug("socket.timeout: %s" % e)
|
|
67
70
|
continue
|
|
@@ -69,7 +72,7 @@ class ThreadedServer(threading.Thread, jsocket_base.JsonServer):
|
|
|
69
72
|
logger.exception(e)
|
|
70
73
|
self._close_connection()
|
|
71
74
|
break
|
|
72
|
-
self.
|
|
75
|
+
self._close_socket()
|
|
73
76
|
|
|
74
77
|
def start(self):
|
|
75
78
|
""" Starts the threaded server.
|
|
@@ -100,7 +103,7 @@ class ServerFactoryThread(threading.Thread, jsocket_base.JsonSocket):
|
|
|
100
103
|
""" Swaps the existing socket with a new one. Useful for setting socket after a new connection.
|
|
101
104
|
|
|
102
105
|
@param new_sock socket to replace the existing default jsocket.JsonSocket object
|
|
103
|
-
@retval
|
|
106
|
+
@retval None
|
|
104
107
|
"""
|
|
105
108
|
del self.socket
|
|
106
109
|
self.socket = new_sock
|
|
@@ -108,21 +111,23 @@ class ServerFactoryThread(threading.Thread, jsocket_base.JsonSocket):
|
|
|
108
111
|
|
|
109
112
|
def run(self):
|
|
110
113
|
""" Should exit when client closes socket conn.
|
|
111
|
-
|
|
114
|
+
Can force an exit with force_stop.
|
|
112
115
|
"""
|
|
113
116
|
while self._isAlive:
|
|
114
117
|
try:
|
|
115
118
|
obj = self.read_obj()
|
|
116
|
-
self._process_message(obj)
|
|
119
|
+
resp_obj = self._process_message(obj)
|
|
120
|
+
if resp_obj is not None:
|
|
121
|
+
logger.debug("message has a response")
|
|
122
|
+
self.send_obj(resp_obj)
|
|
117
123
|
except socket.timeout as e:
|
|
118
124
|
logger.debug("socket.timeout: %s" % e)
|
|
119
125
|
continue
|
|
120
126
|
except Exception as e:
|
|
121
|
-
logger.info("client connection broken,
|
|
122
|
-
self._close_connection()
|
|
127
|
+
logger.info("client connection broken, exit and close connection socket")
|
|
123
128
|
self._isAlive = False
|
|
124
129
|
break
|
|
125
|
-
self.
|
|
130
|
+
self._close_connection()
|
|
126
131
|
|
|
127
132
|
def start(self):
|
|
128
133
|
""" Starts the factory thread.
|
|
@@ -136,7 +141,7 @@ class ServerFactoryThread(threading.Thread, jsocket_base.JsonSocket):
|
|
|
136
141
|
|
|
137
142
|
def force_stop(self):
|
|
138
143
|
""" Force stops the factory thread.
|
|
139
|
-
|
|
144
|
+
Should exit when client socket is closed under normal conditions.
|
|
140
145
|
The life of the dead is in the memory of the living.
|
|
141
146
|
|
|
142
147
|
@retval None
|
|
@@ -180,13 +185,13 @@ class ServerFactory(ThreadedServer):
|
|
|
180
185
|
|
|
181
186
|
def stop_all(self):
|
|
182
187
|
for t in self._threads:
|
|
183
|
-
if t.
|
|
188
|
+
if t.is_alive():
|
|
184
189
|
t.force_stop()
|
|
185
190
|
t.join()
|
|
186
191
|
|
|
187
192
|
def _purge_threads(self):
|
|
188
193
|
for t in self._threads:
|
|
189
|
-
if not t.
|
|
194
|
+
if not t.is_alive():
|
|
190
195
|
self._threads.remove(t)
|
|
191
196
|
|
|
192
197
|
def _wait_to_exit(self):
|
|
@@ -194,6 +199,6 @@ class ServerFactory(ThreadedServer):
|
|
|
194
199
|
time.sleep(0.2)
|
|
195
200
|
|
|
196
201
|
def _get_num_of_active_threads(self):
|
|
197
|
-
return len([True for x in self._threads if x.
|
|
202
|
+
return len([True for x in self._threads if x.is_alive()])
|
|
198
203
|
|
|
199
204
|
active = property(_get_num_of_active_threads, doc="number of active threads")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 1
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: jsocket
|
|
3
|
-
Version: 1.
|
|
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
|
|
@@ -8,12 +8,10 @@ Author-email: chris@cpiekarski.com
|
|
|
8
8
|
Maintainer: Christopher Piekarski
|
|
9
9
|
Maintainer-email: chris@cpiekarski.com
|
|
10
10
|
License: OSI Approved Apache Software License
|
|
11
|
-
Description: UNKNOWN
|
|
12
11
|
Keywords: json,socket,server,client
|
|
13
|
-
Platform: UNKNOWN
|
|
14
12
|
Classifier: Intended Audience :: Developers
|
|
15
13
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
15
|
Classifier: Operating System :: OS Independent
|
|
18
16
|
Classifier: Development Status :: 5 - Production/Stable
|
|
19
17
|
Classifier: Topic :: System :: Networking
|
|
@@ -21,4 +19,5 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
|
21
19
|
Classifier: Topic :: System :: Distributed Computing
|
|
22
20
|
Classifier: Topic :: System :: Hardware :: Symmetric Multi-processing
|
|
23
21
|
Provides: jsocket
|
|
24
|
-
Requires-Python: >=3.
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
License-File: LICENSE
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from setuptools import setup, Extension
|
|
4
4
|
|
|
5
5
|
setup(name='jsocket',
|
|
6
|
-
version='1.
|
|
6
|
+
version='1.9.2',
|
|
7
7
|
description='Python JSON Server & Client',
|
|
8
8
|
author='Christopher Piekarski',
|
|
9
9
|
author_email='chris@cpiekarski.com',
|
|
@@ -13,11 +13,11 @@ setup(name='jsocket',
|
|
|
13
13
|
keywords=['json','socket','server','client'],
|
|
14
14
|
packages=['jsocket'],
|
|
15
15
|
provides=['jsocket'],
|
|
16
|
-
python_requires='>=3.
|
|
16
|
+
python_requires='>=3.9',
|
|
17
17
|
classifiers=[
|
|
18
18
|
'Intended Audience :: Developers',
|
|
19
19
|
'License :: OSI Approved :: Apache Software License',
|
|
20
|
-
'Programming Language :: Python :: 3.
|
|
20
|
+
'Programming Language :: Python :: 3.9',
|
|
21
21
|
'Operating System :: OS Independent',
|
|
22
22
|
'Development Status :: 5 - Production/Stable',
|
|
23
23
|
'Topic :: System :: Networking',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|