Skip to content

Instantly share code, notes, and snippets.

@dhilst
Created April 12, 2020 22:42
Show Gist options
  • Save dhilst/1da0efe00ef64ba9a093d596e9457b20 to your computer and use it in GitHub Desktop.
Save dhilst/1da0efe00ef64ba9a093d596e9457b20 to your computer and use it in GitHub Desktop.
# test with `nc -kl 3000`
# write to nc terminal to send data
import socket
import sys
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Socket successfully created")
except socket.error as err:
print("socket creation failed with error %s" %(err))
s.settimeout(3.0)
s.connect(("localhost", 3000))
r = s.recv(1024)
print(r.decode('ascii'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment