pyInputStreaming/Client.py

25 lines
791 B
Python
Raw Normal View History

2020-06-02 18:10:07 -05:00
#!/usr/bin/python
import socket
import threading
import pyxinput
2020-06-02 22:11:32 -05:00
from time import sleep
2020-06-03 01:07:28 -05:00
import pickle
2020-06-02 18:10:07 -05:00
# Define server ip and port
2020-06-02 22:11:32 -05:00
ip = '192.168.122.1'
2020-06-02 18:10:07 -05:00
port = 2222
# Create virtual controller
MyVirtual = pyxinput.vController()
# Connect to Server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((ip, port))
while True:
2020-06-03 14:15:09 -05:00
from_server = client.makefile(mode='rb')
#Decode Sever message
2020-06-03 14:15:09 -05:00
unpickler = pickle.Unpickler(from_server)
decodedServerData = unpickler.load()
print("Raw Data:", decodedServerData)
# pyxinput will only accept values one at a time, so we need to apply the itme in the dictionary one by one
for event, state in decodedServerData.items():
MyVirtual.set_value(event, state)
print('\''+event+'\''+',', state)