-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
93 lines (65 loc) · 1.85 KB
/
client.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from contextlib import nullcontext
import pyautogui
import socket
import sys
# Create a socket object
s = socket.socket()
ip = str(sys.argv[0])
hostname = str(sys.argv[1])
# Define the port on which you want to connect
port = 12354
port1 = port+1
sizex,sizey = pyautogui.size()
pyautogui.moveTo(sizex/2,sizey/2,duration=0)
# connect to the server on local computer
try:
try:
s.connect((socket.gethostbyname(hostname), port))
except:
s.connect((socket.gethostbyname(hostname), port1))
except:
try:
s.connect((ip, port))
except:
s.connect((ip, port1))
previousx=-1
previousy=-1
recievedx=10
recievedy=10
# receive data from the server and decoding to get the string.
while 1==1:
try:
recieved = s.recv(1024).decode()
print(recieved)
print("test")
if (recieved[0]=="x"):
recievedx=int(recieved[1:])
if (recieved[0]=="y"):
recievedy=int(recieved[1:])
"""if (xpos>0):
if(ypos>xpos):
recievedx = int(recieved[xpos:(ypos-2)])
else:
recievedx = int(recieved[xpos:])
else:
recievedx = 0
if (ypos>0):
if(xpos>ypos):
recievedy = int(recieved[ypos:(xpos-2)])
else:
recievedy = int(recieved[ypos:])
else:
recievedy = 0 """
if(previousx!=-1 and previousy!=-1 and recievedx!=-1 and recievedy!=-1):
xmove= recievedx-previousx
ymove= recievedy-previousy
pyautogui.moveRel(xmove, ymove, duration=0)
previousx = recievedx
previousy = recievedx
except:
print("error in parsing coords")
# close the connection
"""x = 100
y = 100
pyautogui.moveRel(x, y)
pyautogui.moveRel(x, y)"""