forked from teamgonuts/Bond-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
executable file
·61 lines (47 loc) · 1.26 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
import socket
#===============FUNCTIONS=====================#
def legalResponse(var):
if(var == 'load' or \
var == 'hedge30yr' or \
var == 'yield+100bp' or \
var == 'yield-100bp' or \
var == 'close'):
return True
else:
return False
#==============SPAWN SERVER=====================#
import os
import sys
def run(program, *args):
pid = os.fork()
if not pid:
os.execvp(program, (program,) + args)
return os.wait()[0]
run("sh", "run.sh")
#==============CODE===========================#
HOST = socket.gethostname()
PORT = 0x1234
MSGSIZE = 8192
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
done = False;
#Server doesn't need to handle close
var = "go";
s.send(var)
data = s.recv(MSGSIZE)
print 'Received response from the server of:', repr(data)
"""
while(not done):
#getting user input
var = raw_input("Enter Server Command: ")
while(not legalResponse(var)):
var = raw_input("Invalid Command Error!\nEnter Server Command: ")
if(var == 'close'):
done = True
else:
s.send(var)
data = s.recv(MSGSIZE)
print 'Received response from the server of:', repr(data)
"""
s.close()