78 lines
1.5 KiB
Python
Executable file
78 lines
1.5 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import sys, time, 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))
|
|
|
|
# Say hello
|
|
|
|
print "Saying hello to server"
|
|
s.send(
|
|
"Server-Command: hello\n\
|
|
Content-Type: text\n\
|
|
Content-Length: 0\n\
|
|
\n\
|
|
")
|
|
fs = s.makefile()
|
|
data = fs.readline()
|
|
token = data.split(" ")[0]
|
|
print "Token:", token
|
|
print "Data: ", ' '.join(data.split(" ")[1:])
|
|
|
|
# Define ourselves a function!
|
|
|
|
print "Defining a function called myFun"
|
|
s.send(
|
|
"Token: %s\n\
|
|
Server-Command: define\n\
|
|
Content-Type: text\n\
|
|
Content-Length: 49\n\
|
|
\n\
|
|
function myFun() {return 'Hello World!' ;}" % token)
|
|
fs = s.makefile()
|
|
data = fs.readline()
|
|
print "Token:", token
|
|
print "Data: ", ' '.join(data.split(" ")[1:])
|
|
|
|
# Call that function!
|
|
|
|
print "Calling myFun"
|
|
s.send(
|
|
"Token: %s\n\
|
|
Server-Command: call\n\
|
|
Content-Type: text\n\
|
|
Content-Length: 6\n\
|
|
\n\
|
|
myFun" % token)
|
|
fs = s.makefile()
|
|
data = fs.readline()
|
|
print "Token:", token
|
|
print "Data: ", ' '.join(data.split(" ")[1:])
|
|
|
|
s.close()
|
|
|
|
time.sleep(2)
|
|
|
|
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))
|
|
# Call that function!
|
|
|
|
print "Calling myFun"
|
|
s.send(
|
|
"Token: %s\n\
|
|
Server-Command: call\n\
|
|
Content-Type: text\n\
|
|
Content-Length: 6\n\
|
|
\n\
|
|
myFun" % token)
|
|
fs = s.makefile()
|
|
data = fs.readline()
|
|
print "Token:", token
|
|
print "Data: ", ' '.join(data.split(" ")[1:])
|
|
|
|
s.close()
|