forked from sdehm/RAPIDnetworking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendTCP.py
More file actions
40 lines (31 loc) · 777 Bytes
/
SendTCP.py
File metadata and controls
40 lines (31 loc) · 777 Bytes
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
#!/usr/bin/env python3
# Exit codes
# !512 - Fail
# 512 - OK
import socket
from time import sleep
from datetime import datetime
import sys
import struct
if __name__ == "__main__":
msg = sys.argv[1]
else:
exit(0)
def getUTC():
return (datetime.utcnow().isoformat())
msg = getUTC() + " " + msg
# TCP IP/Port and Connect ####################################################################
TCP_IP = '152.228.80.148'
TCP_PORT = 5005
BUFFER_SIZE = 512
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
# Connect & Send #############################################################################
s.send(msg.encode('ascii'))
r = s.recv(BUFFER_SIZE).decode('ascii')
print(r)
s.close()
if(r == "OK"):
exit(1)
else:
exit(0)