-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTCPPython.py
More file actions
43 lines (37 loc) · 1.39 KB
/
TCPPython.py
File metadata and controls
43 lines (37 loc) · 1.39 KB
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
#!/usr/bin/env python
import socket
host = ''
port = 50000
backlog = 5
size = 1024
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.bind((host,port))
socket.listen(backlog)
print("Server Started")
while True:
connection = None
try:
connection, address = socket.accept()
print ("Unity Connected.")
#connection.send("First call from Python\n")
while True:
data = connection.recv(size).decode()
if data:
if data=="Disconnect":
print ("Connection closed by Unity")
connection.close()
exit()
break
else:
valuesList = data.split(",")
xInput = valuesList[0]
yInput= valuesList[1]
zInput= valuesList[2]
floatInput= float (valuesList[3])
intInput= int (valuesList[4])
msg = xInput + "," + yInput + "," + zInput + "," + str(floatInput) + "," + str(intInput) + "\r\n"
connection.send(msg.encode('ascii'))
except KeyboardInterrupt:
if connection:
connection.close()
break