You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>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. </p>
111
107
112
-
<p></p><h4>For the Programmers
108
+
<h3>For the Programmers</h3>
113
109
114
-
</h4><p>def handleConnected(): called when handskake is complete</p>
110
+
<p>def handleConnected(): called when handskake is complete</p>
115
111
116
112
<p>def handleClose(): called when the endpoint is closed or there is an error</p>
117
113
@@ -120,23 +116,21 @@ <h4>TLS/SSL Example</h4>
120
116
<ul>
121
117
<li>self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY)</li>
122
118
<li>self.data: bytearray payload or None if there was no payload</li>
123
-
<li>self.address: address port tuple of the endpoint</li>
124
-
<li>self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler for its use)</li>
119
+
<li>self.address: TCP address port tuple of the endpoint</li>
120
+
<li>self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler)</li>
125
121
<li>self.server.connections: map containing all the clients connected to the server</li>
126
122
</ul><p>def sendMessage(buffer): send some text or binary data to the client endpoint</p>
127
123
128
124
<ul>
129
-
<li>sending a buffer as str() will send a text based WebSocket frame otherwise binary</li>
130
-
</ul><p>def sendClose(): send close frame to enpoint</p>
131
-
</section>
132
-
133
-
<footer>
134
-
SimpleWebSocketServer is maintained by <ahref="https://github.com/opiate">opiate</a><br>
135
-
This page was generated by <ahref="http://pages.github.com">GitHub Pages</a>. Tactile theme by <ahref="http://twitter.com/jasonlong">Jason Long</a>.
136
-
</footer>
137
-
138
-
139
-
</div>
125
+
<li>sending a buffer as str() will send a text based WebSocket frame otherwise a binary frame</li>
126
+
</ul><p>def sendClose() : send close frame to endpoint</p>
127
+
</section>
140
128
</div>
129
+
<footer>
130
+
<p>Project maintained by <ahref="https://github.com/opiate">opiate</a></p>
131
+
<p>Hosted on GitHub Pages — Theme by <ahref="https://github.com/orderedlist">orderedlist</a></p>
{"name":"SimpleWebSocketServer","tagline":"","body":"<h2>A very simple WebSocket Server written in Python</h2>\r\n<h3>No package installation, just one file, enjoy</h3>\r\n\r\nSupports\r\n - Hixie 76 (Safari and iPhone)\r\n - RFC 6455 (All latest browsers)\r\n - TLS/SSL\r\n\r\n<h4>A Simple Echo Server Example</h4>\r\n\r\n1) Write the client code by extending WebSocket\r\n\r\n from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer\r\n \r\n class SimpleEcho(WebSocket):\r\n \r\n def handleMessage(self):\r\n if self.data is None:\r\n self.data = ''\r\n \r\n # echo message back to client\r\n self.sendMessage(str(self.data))\r\n \r\n def handleConnected(self):\r\n print self.address, 'connected'\r\n \r\n def handleClose(self):\r\n print self.address, 'closed'\r\n\r\n server = SimpleWebSocketServer('', 8000, SimpleEcho)\r\n server.serveforever()\r\n\r\n2) Run your code\r\n\r\n3) Open up <i>websocket.html</i> and connect to the server\r\n\r\n<h4>Want to get up and running faster?</h4>\r\n\r\nThere is an example which provides a simple echo and chat server\r\n\r\nEcho Server\r\n\r\n python SimpleExampleServer.py --example echo\r\n\r\nChat Server (open up multiple <i>websocket.html</i> files)\r\n \r\n python SimpleExampleServer.py --example chat\r\n\r\n\r\n<h4>TLS/SSL Example</h4>\r\n\r\n1) Generate a certificate with key\r\n\r\n openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem\r\n \r\n2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory)\r\n\r\n python SimpleExampleServer.py --example chat --ssl 1 --cert ./cert.pem\r\n \r\n3) Offer the certificate to the browser by serving <i>websocket.html</i> through https. \r\nThe HTTPS server will look for cert.pem in the local directory. \r\nEnsure the <i>websocket.html</i> is also in the same directory to where the server is run. \r\n\r\n sudo python SimpleHTTPSServer.py\r\n\r\n4) Open a web browser to: <i>https://localhost:443/websocket.html</i>\r\n\r\n5) Change <i>ws://localhost:8000/</i> to <i>wss://localhost:8000</i> and click connect. \r\n\r\nNote: 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. \r\n\r\n<h4>For the Programmers</h5>\r\n\r\ndef handleConnected(): called when handskake is complete\r\n\r\ndef handleClose(): called when the endpoint is closed or there is an error\r\n\r\ndef handleMessage(): gets called when there is an incoming message from the client endpoint\r\n - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY)\r\n - self.data: bytearray payload or None if there was no payload\r\n - self.address: address port tuple of the endpoint\r\n - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler for its use)\r\n - self.server.connections: map containing all the clients connected to the server\r\n\r\ndef sendMessage(buffer): send some text or binary data to the client endpoint\r\n - sending a buffer as str() will send a text based WebSocket frame otherwise binary\r\n \r\ndef sendClose(): send close frame to enpoint\r\n \r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
1
+
{"name":"SimpleWebSocketServer","tagline":"","body":"<h2>A very simple WebSocket Server written in Python</h2>\r\n<h3 color = red>No package installation, just a single file, enjoy!</h3>\r\n\r\nSupports\r\n - Hixie 76 (Safari and iPhone)\r\n - RFC 6455 (All latest browsers)\r\n - TLS/SSL\r\n\r\n<h3>A Simple Echo Server Example</h3>\r\n\r\n1) Write the client code by extending WebSocket\r\n`````python\r\n from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer\r\n \r\n class SimpleEcho(WebSocket):\r\n \r\n def handleMessage(self):\r\n if self.data is None:\r\n self.data = ''\r\n \r\n # echo message back to client\r\n self.sendMessage(str(self.data))\r\n \r\n def handleConnected(self):\r\n print self.address, 'connected'\r\n \r\n def handleClose(self):\r\n print self.address, 'closed'\r\n\r\n server = SimpleWebSocketServer('', 8000, SimpleEcho)\r\n server.serveforever()\r\n`````\r\n\r\n2) Run your code\r\n\r\n3) Open up <i>websocket.html</i> and connect to the server\r\n\r\n<h4>Want to get up and running faster?</h4>\r\n\r\nThere is an example which provides a simple echo and chat server\r\n\r\nEcho Server\r\n\r\n python SimpleExampleServer.py --example echo\r\n\r\nChat Server (open up multiple <i>websocket.html</i> files)\r\n \r\n python SimpleExampleServer.py --example chat\r\n\r\n\r\n<h3>TLS/SSL Example</h3>\r\n\r\n1) Generate a certificate with key\r\n\r\n openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem\r\n \r\n2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory)\r\n\r\n python SimpleExampleServer.py --example chat --ssl 1 --cert ./cert.pem\r\n \r\n3) Offer the certificate to the browser by serving <i>websocket.html</i> through https. \r\nThe HTTPS server will look for cert.pem in the local directory. \r\nEnsure the <i>websocket.html</i> is also in the same directory to where the server is run. \r\n\r\n sudo python SimpleHTTPSServer.py\r\n\r\n4) Open a web browser to: <i>https://localhost:443/websocket.html</i>\r\n\r\n5) Change <i>ws://localhost:8000/</i> to <i>wss://localhost:8000</i> and click connect. \r\n\r\nNote: 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. \r\n\r\n<h3>For the Programmers</h3>\r\n\r\ndef handleConnected(): called when handskake is complete\r\n\r\ndef handleClose(): called when the endpoint is closed or there is an error\r\n\r\ndef handleMessage(): gets called when there is an incoming message from the client endpoint\r\n - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY)\r\n - self.data: bytearray payload or None if there was no payload\r\n - self.address: TCP address port tuple of the endpoint\r\n - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler)\r\n - self.server.connections: map containing all the clients connected to the server\r\n\r\ndef sendMessage(buffer): send some text or binary data to the client endpoint\r\n - sending a buffer as str() will send a text based WebSocket frame otherwise a binary frame\r\n \r\ndef sendClose() : send close frame to endpoint\r\n \r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
0 commit comments