Begin rewrite of socket connections
This commit is contained in:
parent
fa6e5d8213
commit
66406ed739
@ -13,10 +13,11 @@ MyVirtual = pyxinput.vController()
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
client.connect((ip, port))
|
||||
while True:
|
||||
from_server = client.recv(8144)
|
||||
from_server = client.makefile(mode='rb')
|
||||
#Decode Sever message
|
||||
decodedServerData = pickle.loads(from_server)
|
||||
print("Raw Data:", str(decodedServerData))
|
||||
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)
|
||||
|
24
Server.py
24
Server.py
@ -18,20 +18,20 @@ controllerData = ""
|
||||
controllerDataDict = {'AxisLx': 0, 'AxisLy': 0, 'AxisRx': 0, 'AxisRy': 0, 'BtnBack': 0, 'BtnStart': 0, 'BtnA': 0, 'BtnB': 0, 'BtnX': 0, 'BtnY': 0, 'BtnThumbL': 0, 'BtnThumbR': 0, 'BtnShoulderL': 0, 'BtnShoulderR': 0, 'Dpad': 0, 'TriggerL': 0, 'TriggerR': 0}
|
||||
#Lookup table to convert values from the "inputs" library
|
||||
lookup_table = {'ABS_X': 'AxisLx', 'ABS_Y': 'AxisLy', 'ABS_RX': 'AxisRx', 'ABS_RY': 'AxisRy', 'BTN_SELECT': 'BtnBack', 'BTN_START': 'BtnStart', 'BTN_SOUTH': 'BtnA', 'BTN_EAST': 'BtnB', 'BTN_NORTH': 'BtnX', 'BTN_WEST': 'BtnY', 'BTN_THUMBL': 'BtnThumbL', 'BTN_THUMBR': 'BtnThumbR', 'BTN_TL': 'BtnShoulderL', 'BTN_TR': 'BtnShoulderR', 'ABS_Z': 'TriggerL', 'ABS_RZ': 'TriggerR'}
|
||||
print("Waiting for connection...")
|
||||
#print("Waiting for connection...")
|
||||
def sendData():
|
||||
#Pickle for transmittion
|
||||
encodedControllerData = pickle.dumps(controllerDataDict)
|
||||
encodedControllerData = pickle.Pickler(controllerDataDict)
|
||||
#print(encodedControllerData)
|
||||
conn.send(encodedControllerData)
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind((ip, port))
|
||||
s.listen(1)
|
||||
#s.setblocking(False)
|
||||
conn, addr = s.accept()
|
||||
with conn:
|
||||
print(colored('Connected by', 'red'), addr)
|
||||
print(controllerDataDict)
|
||||
pickler.dump(encodedControllerData)
|
||||
file.flush()
|
||||
#Create Socket
|
||||
conn = socket.create_server((ip, port))
|
||||
file = conn.makefile(mode='wb')
|
||||
pickler = pickle.Pickler(file)
|
||||
#print(colored('Connected by', 'red'), addr)
|
||||
print(controllerDataDict)
|
||||
with conn:
|
||||
while True:
|
||||
events = get_gamepad()
|
||||
for event in events:
|
||||
@ -70,5 +70,3 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
# Add values to controllerDataDict
|
||||
controllerDataDict[lookup_table[str(event.code)]] = event.state
|
||||
sendData()
|
||||
#Execute everything
|
||||
controllerLoop()
|
||||
|
Loading…
Reference in New Issue
Block a user