diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-05 13:03:28 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-05 13:03:28 +0000 |
| commit | e069694405736eac9ee535b65f82b0cbe9bdf1e6 (patch) | |
| tree | 3a4bca451dd7536bb1735e14ba6805d19b82851b | |
| parent | 7c3eac72b9ad2a1cd9b9c0de47fa57627fa30dab (diff) | |
automatic import of python-simple-websocket-serveropeneuler20.03
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-simple-websocket-server.spec | 471 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 473 insertions, 0 deletions
@@ -0,0 +1 @@ +/simple-websocket-server-0.4.2.tar.gz diff --git a/python-simple-websocket-server.spec b/python-simple-websocket-server.spec new file mode 100644 index 0000000..b823cb8 --- /dev/null +++ b/python-simple-websocket-server.spec @@ -0,0 +1,471 @@ +%global _empty_manifest_terminate_build 0 +Name: python-simple-websocket-server +Version: 0.4.2 +Release: 1 +Summary: A simple WebSocket server +License: MIT +URL: https://github.com/pikhovkin/simple-websocket-server +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ad/31/1acb094a1c161457ce68249741d1f4036998d070e346b6e220bc468edbec/simple-websocket-server-0.4.2.tar.gz +BuildArch: noarch + + +%description +# A simple WebSocket server + +[](https://github.com/pikhovkin/simple-websocket-server/actions) +[](https://pypi.org/project/simple-websocket-server/) + +[](./LICENSE) + +Based on [simple-websocket-server](https://github.com/dpallot/simple-websocket-server). + +- RFC 6455 (All latest browsers) +- TLS/SSL out of the box +- Passes Autobahns Websocket Testsuite +- Support for Python 2 and 3 + +#### Installation + + pip install simple-websocket-server + +#### Echo Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleEcho(WebSocket): + def handle(self): + # echo message back to client + self.send_message(self.data) + + def connected(self): + print(self.address, 'connected') + + def handle_close(self): + print(self.address, 'closed') + + +server = WebSocketServer('', 8000, SimpleEcho) +server.serve_forever() +````` + +Open *tests/websocket.html* and connect to the server. + +#### Chat Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleChat(WebSocket): + def handle(self): + for client in clients: + if client != self: + client.send_message(self.address[0] + u' - ' + self.data) + + def connected(self): + print(self.address, 'connected') + for client in clients: + client.send_message(self.address[0] + u' - connected') + clients.append(self) + + def handle_close(self): + clients.remove(self) + print(self.address, 'closed') + for client in clients: + client.send_message(self.address[0] + u' - disconnected') + + +clients = [] + +server = WebSocketServer('', 8000, SimpleChat) +server.serve_forever() +````` +Open multiple *tests/websocket.html* and connect to the server. + +#### Want to get up and running faster? + +There is an example which provides a simple echo and chat server + +Echo Server + + python tests/example_server.py --example echo + +Chat Server (open up multiple *tests/websocket.html* files) + + python tests/example_server.py --example chat + +#### TLS/SSL Example + +1) Generate a certificate with key + + openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem + +2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory) + + python tests/example_server.py --example chat --ssl 1 + +3) Offer the certificate to the browser by serving *tests/websocket.html* through https. +The HTTPS server will look for cert.pem in the local directory. +Ensure the *tests/websocket.html* is also in the same directory to where the server is run. + + python tests/simple_https_server.py + +4) Open a web browser to: *https://localhost:443/tests/websocket.html* + +5) Change *ws://localhost:8000/* to *wss://localhost:8000* and click connect. + +Note: if you are having problems connecting, ensure that the certificate is added in your browser against the exception *https://localhost:8000* or whatever host:port pair you want to connect to. + +#### For the Programmers + +connected: called when handshake is complete + - self.address: TCP address port tuple of the endpoint + +handle_close: called when the endpoint is closed or there is an error + - self.address: TCP address port tuple of the endpoint + +handle: gets called when there is an incoming message from the client endpoint + - self.address: TCP address port tuple of the endpoint + - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY) + - self.data: bytearray (BINARY frame) or unicode string payload (TEXT frame) + - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler) + +send_message: send some text or binary data to the client endpoint + - sending data as a unicode object will send a TEXT frame + - sending data as a bytearray object will send a BINARY frame + +close: send close frame to endpoint + +### Licensing + +MIT + + + + +%package -n python3-simple-websocket-server +Summary: A simple WebSocket server +Provides: python-simple-websocket-server +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-simple-websocket-server +# A simple WebSocket server + +[](https://github.com/pikhovkin/simple-websocket-server/actions) +[](https://pypi.org/project/simple-websocket-server/) + +[](./LICENSE) + +Based on [simple-websocket-server](https://github.com/dpallot/simple-websocket-server). + +- RFC 6455 (All latest browsers) +- TLS/SSL out of the box +- Passes Autobahns Websocket Testsuite +- Support for Python 2 and 3 + +#### Installation + + pip install simple-websocket-server + +#### Echo Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleEcho(WebSocket): + def handle(self): + # echo message back to client + self.send_message(self.data) + + def connected(self): + print(self.address, 'connected') + + def handle_close(self): + print(self.address, 'closed') + + +server = WebSocketServer('', 8000, SimpleEcho) +server.serve_forever() +````` + +Open *tests/websocket.html* and connect to the server. + +#### Chat Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleChat(WebSocket): + def handle(self): + for client in clients: + if client != self: + client.send_message(self.address[0] + u' - ' + self.data) + + def connected(self): + print(self.address, 'connected') + for client in clients: + client.send_message(self.address[0] + u' - connected') + clients.append(self) + + def handle_close(self): + clients.remove(self) + print(self.address, 'closed') + for client in clients: + client.send_message(self.address[0] + u' - disconnected') + + +clients = [] + +server = WebSocketServer('', 8000, SimpleChat) +server.serve_forever() +````` +Open multiple *tests/websocket.html* and connect to the server. + +#### Want to get up and running faster? + +There is an example which provides a simple echo and chat server + +Echo Server + + python tests/example_server.py --example echo + +Chat Server (open up multiple *tests/websocket.html* files) + + python tests/example_server.py --example chat + +#### TLS/SSL Example + +1) Generate a certificate with key + + openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem + +2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory) + + python tests/example_server.py --example chat --ssl 1 + +3) Offer the certificate to the browser by serving *tests/websocket.html* through https. +The HTTPS server will look for cert.pem in the local directory. +Ensure the *tests/websocket.html* is also in the same directory to where the server is run. + + python tests/simple_https_server.py + +4) Open a web browser to: *https://localhost:443/tests/websocket.html* + +5) Change *ws://localhost:8000/* to *wss://localhost:8000* and click connect. + +Note: if you are having problems connecting, ensure that the certificate is added in your browser against the exception *https://localhost:8000* or whatever host:port pair you want to connect to. + +#### For the Programmers + +connected: called when handshake is complete + - self.address: TCP address port tuple of the endpoint + +handle_close: called when the endpoint is closed or there is an error + - self.address: TCP address port tuple of the endpoint + +handle: gets called when there is an incoming message from the client endpoint + - self.address: TCP address port tuple of the endpoint + - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY) + - self.data: bytearray (BINARY frame) or unicode string payload (TEXT frame) + - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler) + +send_message: send some text or binary data to the client endpoint + - sending data as a unicode object will send a TEXT frame + - sending data as a bytearray object will send a BINARY frame + +close: send close frame to endpoint + +### Licensing + +MIT + + + + +%package help +Summary: Development documents and examples for simple-websocket-server +Provides: python3-simple-websocket-server-doc +%description help +# A simple WebSocket server + +[](https://github.com/pikhovkin/simple-websocket-server/actions) +[](https://pypi.org/project/simple-websocket-server/) + +[](./LICENSE) + +Based on [simple-websocket-server](https://github.com/dpallot/simple-websocket-server). + +- RFC 6455 (All latest browsers) +- TLS/SSL out of the box +- Passes Autobahns Websocket Testsuite +- Support for Python 2 and 3 + +#### Installation + + pip install simple-websocket-server + +#### Echo Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleEcho(WebSocket): + def handle(self): + # echo message back to client + self.send_message(self.data) + + def connected(self): + print(self.address, 'connected') + + def handle_close(self): + print(self.address, 'closed') + + +server = WebSocketServer('', 8000, SimpleEcho) +server.serve_forever() +````` + +Open *tests/websocket.html* and connect to the server. + +#### Chat Server Example + +`````python +from simple_websocket_server import WebSocketServer, WebSocket + + +class SimpleChat(WebSocket): + def handle(self): + for client in clients: + if client != self: + client.send_message(self.address[0] + u' - ' + self.data) + + def connected(self): + print(self.address, 'connected') + for client in clients: + client.send_message(self.address[0] + u' - connected') + clients.append(self) + + def handle_close(self): + clients.remove(self) + print(self.address, 'closed') + for client in clients: + client.send_message(self.address[0] + u' - disconnected') + + +clients = [] + +server = WebSocketServer('', 8000, SimpleChat) +server.serve_forever() +````` +Open multiple *tests/websocket.html* and connect to the server. + +#### Want to get up and running faster? + +There is an example which provides a simple echo and chat server + +Echo Server + + python tests/example_server.py --example echo + +Chat Server (open up multiple *tests/websocket.html* files) + + python tests/example_server.py --example chat + +#### TLS/SSL Example + +1) Generate a certificate with key + + openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem + +2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory) + + python tests/example_server.py --example chat --ssl 1 + +3) Offer the certificate to the browser by serving *tests/websocket.html* through https. +The HTTPS server will look for cert.pem in the local directory. +Ensure the *tests/websocket.html* is also in the same directory to where the server is run. + + python tests/simple_https_server.py + +4) Open a web browser to: *https://localhost:443/tests/websocket.html* + +5) Change *ws://localhost:8000/* to *wss://localhost:8000* and click connect. + +Note: if you are having problems connecting, ensure that the certificate is added in your browser against the exception *https://localhost:8000* or whatever host:port pair you want to connect to. + +#### For the Programmers + +connected: called when handshake is complete + - self.address: TCP address port tuple of the endpoint + +handle_close: called when the endpoint is closed or there is an error + - self.address: TCP address port tuple of the endpoint + +handle: gets called when there is an incoming message from the client endpoint + - self.address: TCP address port tuple of the endpoint + - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY) + - self.data: bytearray (BINARY frame) or unicode string payload (TEXT frame) + - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler) + +send_message: send some text or binary data to the client endpoint + - sending data as a unicode object will send a TEXT frame + - sending data as a bytearray object will send a BINARY frame + +close: send close frame to endpoint + +### Licensing + +MIT + + + + +%prep +%autosetup -n simple-websocket-server-0.4.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-simple-websocket-server -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 0.4.2-1 +- Package Spec generated @@ -0,0 +1 @@ +47c07fcc9b7c636282f6843283dda50b simple-websocket-server-0.4.2.tar.gz |
