This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
GGS/python_client

42 lines
800 B
Python
Executable file

#!/usr/bin/env python
import sys
import socket
HOST = 'localhost' # The remote host
PORT = int(sys.argv[1]) # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# Define ourselves a function!
s.send(
"Token: 1001\n\
Command: define\n\
Content-Type: text\n\
Content-Length: 42\n\
\n\
function myFun() {return 'Hello world!' ;}")
fs = s.makefile()
data = fs.readline()
token = data.split(" ")[0]
print "Token:", token
print "Data: ", ' '.join(data.split(" ")[1:])
# Call that function!
s.send(
"Token: 1001\n\
Command: call\n\
Content-Type: text\n\
Content-Length: 6\n\
\n\
myFun()")
fs = s.makefile()
data = fs.readline()
token = data.split(" ")[0]
print "Token:", token
print "Data: ", ' '.join(data.split(" ")[1:])
s.close()