Skip to content

Instantly share code, notes, and snippets.

@vklachkov
Created April 14, 2020 18:03
Show Gist options
  • Save vklachkov/6e286985ccc89a553a91ef88a982abc8 to your computer and use it in GitHub Desktop.
Save vklachkov/6e286985ccc89a553a91ef88a982abc8 to your computer and use it in GitHub Desktop.
Simple tcp server
import socket
import time
SERVER_ADDRESS = ('localhost', 2353)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(SERVER_ADDRESS)
server_socket.listen(1)
while True:
try:
connection, address = server_socket.accept()
print("new connection from {address}".format(address=address))
c = 1
while True:
connection.send(bytes(str(c), encoding='UTF-8'))
c += 1
time.sleep(0.05);
except:
time.sleep(0.2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment