Skip to content

Instantly share code, notes, and snippets.

@girasquid
Created February 11, 2010 05:25
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 girasquid/301254 to your computer and use it in GitHub Desktop.
Save girasquid/301254 to your computer and use it in GitHub Desktop.
## I'm not sure where I found this, or who to attribute it to. Thanks, whoever you are!
import sys
import time
import socket
import marshal
# the dumbest code you will ever see. i love it.
def server():
def func():
return 1 + 1
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("127.0.0.1", 5667))
sock.listen(1)
while True:
s, addr = sock.accept()
s.send(marshal.dumps(func.func_code))
ret = marshal.loads(s.recv(1000))
print repr(ret)
s.close()
def client():
# connect to code server
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", 5667))
serialized_code = sock.recv(1000)
func = lambda: 0
func.func_code = marshal.loads(serialized_code)
ret = func()
sock.send(marshal.dumps(ret))
sock.close()
def main():
if sys.argv[1] == "server":
server()
elif sys.argv[1] == "client":
client()
else:
print "unknown type"
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment