-
Notifications
You must be signed in to change notification settings - Fork 3
/
simpleClient.py
36 lines (31 loc) · 885 Bytes
/
simpleClient.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
import socket
import sys
host = '192.168.1.186'
port = 5561
def setupSocket():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
return s
def sendReceive(s, message):
s.send(str.encode(message))
reply = s.recv(1024)
print("We have received a reply")
print("Send closing message.")
s.send(str.encode("EXIT"))
s.close()
reply = reply.decode('utf-8')
return reply
def transmit(message):
s = setupSocket()
response = sendReceive(s, message)
return response
print("This is the name of the script: " + sys.argv[0])
print("Number of arguments: " + str(len(sys.argv)))
print("The arguments are: " + str(sys.argv))
command = str(sys.argv[1])
print("Sending command to server: " + command)
try:
response = transmit(command)
except KeyboardInterrupt:
print("Ctrl C")
print("Response: " + response )