How to control PC from anywhere using Python?
Prerequisite – Socket programming in Python
In this solution, we use the concept of Socket Programming for establishing communication between two computers.
Socket Programming in Python
Socket Programming is a way of connecting two systems on a network to communicate with each other. Sockets are the endpoints built for sending and receiving data and it is a combination of IP address and port. We will import the socket module to use Socket Programming in Python. The following are the methods required to build the solution:
Methods in Socket Module:
Method Description socket.socket(). Create sockets. socket.bind() This method bind hostname and portname to socket. socket.listen() This method starts the TCP listener. socket.accept() Accept client connection and wait until the connection arrives. socket.connect() Initiate TCP connection. socket.close() Close the socket.
Other Socket Methods:
|s.recv()||It receives TCP message|
|s.send()||It sends TCP message|
|socket.gethostname()||It returns hostname|
So we have to develop two python programs one is master.py (server)and another is slave.py (client), using master.py we can control the system having slave.py program. To control the pc from anywhere using python please the follow the step mentioned below:
Step 1: Create and Execute the “master.py” in one terminal
Step 2: Create and Execute the “slave.py” is another terminal