-
-
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
This file contains 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
# 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