Skip to content

Instantly share code, notes, and snippets.

@jeffvestal
Created July 27, 2020 13:37
Show Gist options
  • Save jeffvestal/2484d1c9d165661183c685bf2b2bc591 to your computer and use it in GitHub Desktop.
Save jeffvestal/2484d1c9d165661183c685bf2b2bc591 to your computer and use it in GitHub Desktop.
Super simply python client that will listen on a port and reply with received
# python socket info https://docs.python.org/3/library/socket.html
import socket
PORT = 65432
s = socket.socket()
HOST = socket.gethostname()
s.bind((HOST, PORT))
s.listen(5)
print ('Python port listener active')
print('\n This can be tested with: \n`echo Bob Belcher |nc %s %s`\nYou shoud get the message "received"\n' % (HOST, PORT))
while True:
print('starting up socket')
conn, addr = s.accept()
print ('Got connection from', addr)
data = conn.recv(1024)
print('Server received', repr(data))
print(data)
print('Done sending')
conn.send(b'received')
conn.close()
print('connection closed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment