Skip to content

Instantly share code, notes, and snippets.

@tbhaxor
Created November 30, 2019 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbhaxor/5b1021ccdf8088de98f9bade1e9d2d52 to your computer and use it in GitHub Desktop.
Save tbhaxor/5b1021ccdf8088de98f9bade1e9d2d52 to your computer and use it in GitHub Desktop.
simple tcp server
from socket import socket, SOCK_STREAM, AF_INET
from sys import argv
argv.pop(0)
# instancing the server
server = socket(AF_INET, SOCK_STREAM)
# binding it to network interface
try:
server.bind(("0.0.0.0", int(argv[0])))
except IndexError:
print("[!] Setting default port to 8090")
server.bind(("0.0.0.0", 8090))
print("[#] Listening to the Server")
print("[!] Press CTRL-C to Exit")
server.listen(1)
while True:
# accepting client connection
client, address = server.accept()
# printing client info
print("[!] Got Connection From: %s:%d" % (address[0], address[1]))
# sending the data to client
client.send("hi\n".encode())
# freeing up the resources
client.close()
server.close()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment