flask-socket · 22.03.2016 · from 1973 to 1974, cerf's networking research group at...
TRANSCRIPT
![Page 1: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/1.jpg)
FLASK-SOCKET.IOWeb Sockets Made Simple
![Page 2: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/2.jpg)
WEB SOCKETS!
![Page 3: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/3.jpg)
OK. BUT,
WHY?
![Page 4: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/4.jpg)
FIRST THERE WAS THE INTERNET
![Page 5: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/5.jpg)
AND THEN THERE WAS TCP/IP
![Page 6: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/6.jpg)
TCP/IP SOCKETS
import socketsock = socket.create_connection(('24.244.4.54', 80), timeout=30) try: # Send the request sock.sendall("Really important stuff") # Get the response response = sock.recv(1024) # Bytesfinally: sock.close()
![Page 7: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/7.jpg)
TCP/IP SOCKETS
➤ Real time ➤ Reliable delivery ➤ No standards for delivery
➤ … just bits on the wire
➤ Requires persistent connection
![Page 8: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/8.jpg)
BUT…
I HAVE A 90 MHZ PROCESSOR AND 16 MB OF RAM
![Page 9: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/9.jpg)
![Page 10: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/10.jpg)
“From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification
![Page 11: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/11.jpg)
➤ 4 74181 ALUs (~45 MHz)
➤ 128-512 KB of RAM
➤ 2.5 MB Single Platter Storage Cartridge
![Page 12: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/12.jpg)
HTTP
![Page 13: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/13.jpg)
HTTP
➤ Request / Response
➤ Disconnect TCP socket after response
➤ Meta-data
➤ Information about the payload
➤ Date/time sent
➤ Caching
➤ etc…
➤ Lighter on server resources
➤ The Web!
![Page 14: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/14.jpg)
HTTP Request
POST /example?key=value&something=other HTTP 1.1
Host: www.example.com
Accept: application/json, application/xml
Accept-Language: EN-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
Connection: Keep-Alive
{ "Content": "Adding my content", "Other": [2, 4, 6, 8] }
http://www.example.com/example?key=value&something=other
![Page 15: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/15.jpg)
HTTP (W/ REQUESTS)
import requestsresponse = requests.get('http://www.google.ca')
![Page 16: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/16.jpg)
UH, SO…
SECURITY?
![Page 17: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/17.jpg)
WHAT
ABOUT
IP
ADDRESSES?
![Page 18: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/18.jpg)
BRAVE NEW WORLD (OF NETWORKS)
➤ Network Address Translation (NAT)
➤ Closed ports (pretty much web only)
➤ Security first
➤ ….
![Page 19: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/19.jpg)
HTTP 1.1
![Page 20: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/20.jpg)
WEB SOCKETS!
![Page 21: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/21.jpg)
WEB SOCKETS
➤ Upgrade from a standard HTTP request
➤ Can navigate the modern NAT
➤ Can be authenticated
➤ More secure
![Page 22: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/22.jpg)
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Origin: http://example.com
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
![Page 23: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/23.jpg)
FLASK-SOCKET.IOWeb Sockets Made Simple
![Page 24: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/24.jpg)
OH, BUT FIRST LETS CHECK OUT
FLASK
![Page 25: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/25.jpg)
FLASK
from flask import Flaskapp = Flask(__name__)@app.route("/") def hello(): return "Hello World!"if __name__ == "__main__": app.run()
![Page 26: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/26.jpg)
AND
SOCKET.IO
TOO
![Page 27: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/27.jpg)
SOCKET.IO CLIENT
<script src="/socket.io/socket.io.js"></script> <script> var socket = io('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); });</script>
![Page 28: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/28.jpg)
SOCKET.IO
➤ Channels
➤ Namespaces
➤ Rooms (server-side)
![Page 29: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/29.jpg)
FLASK-SOCKET.IOWeb Sockets Made Simple
![Page 30: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/30.jpg)
FLASK-SOCKET.IO
from flask import Flaskfrom flask_socketio import SocketIOapp = Flask(__name__)app.config['SECRET_KEY'] = 'secret!'socketio = SocketIO(app)@socketio.on('channel') def handle_message(message): print('received message: ' + message)if __name__ == '__main__': socketio.run(app)
![Page 31: FLASK-SOCKET · 22.03.2016 · From 1973 to 1974, Cerf's networking research group at Stanford worked out details of the idea, resulting in the first TCP specification 4 74181](https://reader033.vdocument.in/reader033/viewer/2022053023/6055ec9235e11d3f2d0d116b/html5/thumbnails/31.jpg)
DEMO