Skip to content

Commit 7891f4c

Browse files
committed
Create gh-pages branch via GitHub
1 parent efae39f commit 7891f4c

File tree

6 files changed

+488
-127
lines changed

6 files changed

+488
-127
lines changed

images/checker.png

250 Bytes
Loading

index.html

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,66 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
4-
<meta charset='utf-8'>
4+
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="chrome=1">
6-
<link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
7-
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
8-
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen" />
9-
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
6+
<title>SimpleWebSocketServer by opiate</title>
7+
8+
<link rel="stylesheet" href="stylesheets/styles.css">
9+
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
10+
<script src="javascripts/scale.fix.js"></script>
11+
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
12+
1013
<!--[if lt IE 9]>
1114
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
1215
<![endif]-->
13-
<title>SimpleWebSocketServer by opiate</title>
1416
</head>
15-
1617
<body>
17-
<div id="container">
18-
<div class="inner">
19-
20-
<header>
21-
<h1>SimpleWebSocketServer</h1>
22-
<h2></h2>
23-
</header>
24-
25-
<section id="downloads" class="clearfix">
26-
<a href="https://github.com/opiate/SimpleWebSocketServer/zipball/master" id="download-zip" class="button"><span>Download .zip</span></a>
27-
<a href="https://github.com/opiate/SimpleWebSocketServer/tarball/master" id="download-tar-gz" class="button"><span>Download .tar.gz</span></a>
28-
<a href="https://github.com/opiate/SimpleWebSocketServer" id="view-on-github" class="button"><span>View on GitHub</span></a>
29-
</section>
30-
31-
<hr>
32-
33-
<section id="main_content">
34-
<h2>A very simple WebSocket Server written in Python</h2>
35-
36-
<h3>No package installation, just one file, enjoy</h3>
18+
<div class="wrapper">
19+
<header class="without-description">
20+
<h1>SimpleWebSocketServer</h1>
21+
<p></p>
22+
<p class="view"><a href="https://github.com/opiate/SimpleWebSocketServer">View the Project on GitHub <small>opiate/SimpleWebSocketServer</small></a></p>
23+
<ul>
24+
<li><a href="https://github.com/opiate/SimpleWebSocketServer/zipball/master">Download <strong>ZIP File</strong></a></li>
25+
<li><a href="https://github.com/opiate/SimpleWebSocketServer/tarball/master">Download <strong>TAR Ball</strong></a></li>
26+
<li><a href="https://github.com/opiate/SimpleWebSocketServer">View On <strong>GitHub</strong></a></li>
27+
</ul>
28+
</header>
29+
<section>
30+
<h2>A very simple WebSocket Server written in Python</h2>
31+
32+
<h3 color="red">No package installation, just a single file, enjoy!</h3>
3733

3834
<p>Supports</p>
3935

4036
<ul>
4137
<li>Hixie 76 (Safari and iPhone)</li>
4238
<li>RFC 6455 (All latest browsers)</li>
4339
<li>TLS/SSL</li>
44-
</ul><h4>A Simple Echo Server Example</h4>
40+
</ul><h3>A Simple Echo Server Example</h3>
4541

4642
<p>1) Write the client code by extending WebSocket</p>
4743

48-
<pre><code>from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer
44+
<div class="highlight"><pre> <span class="kn">from</span> <span class="nn">SimpleWebSocketServer</span> <span class="kn">import</span> <span class="n">WebSocket</span><span class="p">,</span> <span class="n">SimpleWebSocketServer</span>
4945

50-
class SimpleEcho(WebSocket):
46+
<span class="k">class</span> <span class="nc">SimpleEcho</span><span class="p">(</span><span class="n">WebSocket</span><span class="p">):</span>
5147

52-
def handleMessage(self):
53-
if self.data is None:
54-
self.data = ''
48+
<span class="k">def</span> <span class="nf">handleMessage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
49+
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
50+
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">''</span>
5551

56-
# echo message back to client
57-
self.sendMessage(str(self.data))
52+
<span class="c"># echo message back to client</span>
53+
<span class="bp">self</span><span class="o">.</span><span class="n">sendMessage</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">))</span>
5854

59-
def handleConnected(self):
60-
print self.address, 'connected'
55+
<span class="k">def</span> <span class="nf">handleConnected</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
56+
<span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="s">'connected'</span>
6157

62-
def handleClose(self):
63-
print self.address, 'closed'
58+
<span class="k">def</span> <span class="nf">handleClose</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
59+
<span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="s">'closed'</span>
6460

65-
server = SimpleWebSocketServer('', 8000, SimpleEcho)
66-
server.serveforever()
67-
</code></pre>
61+
<span class="n">server</span> <span class="o">=</span> <span class="n">SimpleWebSocketServer</span><span class="p">(</span><span class="s">''</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">SimpleEcho</span><span class="p">)</span>
62+
<span class="n">server</span><span class="o">.</span><span class="n">serveforever</span><span class="p">()</span>
63+
</pre></div>
6864

6965
<p>2) Run your code</p>
7066

@@ -84,7 +80,7 @@ <h4>Want to get up and running faster?</h4>
8480
<pre><code>python SimpleExampleServer.py --example chat
8581
</code></pre>
8682

87-
<h4>TLS/SSL Example</h4>
83+
<h3>TLS/SSL Example</h3>
8884

8985
<p>1) Generate a certificate with key</p>
9086

@@ -109,9 +105,9 @@ <h4>TLS/SSL Example</h4>
109105

110106
<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>
111107

112-
<p></p><h4>For the Programmers
108+
<h3>For the Programmers</h3>
113109

114-
</h4><p>def handleConnected(): called when handskake is complete</p>
110+
<p>def handleConnected(): called when handskake is complete</p>
115111

116112
<p>def handleClose(): called when the endpoint is closed or there is an error</p>
117113

@@ -120,23 +116,21 @@ <h4>TLS/SSL Example</h4>
120116
<ul>
121117
<li>self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY)</li>
122118
<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>
125121
<li>self.server.connections: map containing all the clients connected to the server</li>
126122
</ul><p>def sendMessage(buffer): send some text or binary data to the client endpoint</p>
127123

128124
<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 <a href="https://github.com/opiate">opiate</a><br>
135-
This page was generated by <a href="http://pages.github.com">GitHub Pages</a>. Tactile theme by <a href="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>
140128
</div>
129+
<footer>
130+
<p>Project maintained by <a href="https://github.com/opiate">opiate</a></p>
131+
<p>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></p>
132+
</footer>
133+
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
134+
141135
</body>
142136
</html>

javascripts/scale.fix.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fixScale = function(doc) {
2+
3+
var addEvent = 'addEventListener',
4+
type = 'gesturestart',
5+
qsa = 'querySelectorAll',
6+
scales = [1, 1],
7+
meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
8+
9+
function fix() {
10+
meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
11+
doc.removeEventListener(type, fix, true);
12+
}
13+
14+
if ((meta = meta[meta.length - 1]) && addEvent in doc) {
15+
fix();
16+
scales = [.25, 1.6];
17+
doc[addEvent](type, fix, true);
18+
}
19+
20+
};

params.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"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

Comments
 (0)