Getting Start¶
Installation¶
Just use pip command to install Connector to your local Python environment:
pip install tcp-connector
PyPI not support name Connector, so on PyPI it’s named as tcp-connector. But in Python environment, you should import Connector
instead of tcp-connector
. After installed, try following code in Python. If this statement won’t throw exception, that means your installation is succeeded.
>>> from Connector import *
Get connected¶
Connector works in Client/Server mode. So if you want to communicate between some computers, you should choose one computers work as a server, other computers work as a clients and should connect with server. So you should use following steps to get all computers connected:
You have some computers connected in the one Local Area Network.
Choose one computer works as server. Other computers work as clients.
On server computer, run code
server = Server(ip, port_number)
. Ifport_number
gives nothing, it will use a random avaiable port. If bothip
andport_number
give nothing, it will use first avaiable network interface card’s ip.On server computer, you can use
print(server.address)
to get address of server. Such that it print('192.168.199.210', 57680)
. Note it on your notebook.On each client computer, run following code to connect with server:
client = Client() client.connect('192.168.199.210', 57680) # use the address you note on notebook
On server computer, you can get each client peer by this way:
server.clients[0] # to get first connected client server.clients[('192.168.105.23', 8273)] # to get client whose address is ('192.168.105.23', 8273)
client peer means a communication handle on server side that connected with one client.
After that, you got server
object on server computer and client
object on each client computer. Let’s use Connector to communicate with each other!