Created
November 13, 2017 14:20
-
-
Save rambabusaravanan/a0811f8c9bff440f06ca04d06abdd363 to your computer and use it in GitHub Desktop.
Simple TCP Streaming Server Client in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Streaming Client | |
import socket | |
HOST = 'localhost' | |
PORT = 50007 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((HOST, PORT)) | |
while True: | |
data = s.recv(1024) | |
print (repr(data)) | |
s.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Streaming Server | |
import socket | |
import time | |
from random import randint | |
HOST = 'localhost' | |
PORT = 50007 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(1) | |
while True: | |
conn, addr = s.accept() | |
print 'Client connection accepted ', addr | |
while True: | |
try: | |
data = str(randint(0, 9)) | |
print 'Server sent:', data | |
conn.send(data) | |
time.sleep(1) | |
except socket.error, msg: | |
print 'Client connection closed', addr | |
break | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment