Created
February 11, 2010 05:25
-
-
Save girasquid/301254 to your computer and use it in GitHub Desktop.
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
## 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