Skip to content

Instantly share code, notes, and snippets.

@theonewolf
Created October 26, 2011 19:51
Show Gist options
  • Save theonewolf/1317586 to your computer and use it in GitHub Desktop.
Save theonewolf/1317586 to your computer and use it in GitHub Desktop.
Python Socket in Flask Example
#!/usr/bin/env python
import socket
from flask import Flask
app = Flask(__name__)
DEBUG = True
app.config.from_object(__name__)
@app.route('/sockme')
def sockme():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('www.google.com', 80))
s.send('GET / HTTP/1.1\r\n\r\n')
return s.recv(4096)
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment