Skip to content

Instantly share code, notes, and snippets.

@amir-rahnama
Created November 20, 2015 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amir-rahnama/a39290c99a1cb2d6bbad to your computer and use it in GitHub Desktop.
Save amir-rahnama/a39290c99a1cb2d6bbad to your computer and use it in GitHub Desktop.
A simple Python Socket Server
import socket
import random
HOST = '127.0.0.1'
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
# Make sure you add the '\n' at the end of the stream
while 1:
data = 'some_string' + '\n'
conn.send(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment