Linux Format

IP ADDRESSES AND LOCALHOST

-

An IP (internet protocol) address identifies a device on the internet or on a local area network (LAN) if an internet connection exists. An IP address can be identified by four numbers separated by three full-stops. For example a valid IP address could be 172.168.1.212. A local host address is always referred to as 127.0.0.1 and is also known as the loopback address.

In Multiplaye­r Demonstrat­ion mode, which this tutorial is based on, only local host addresses are used in both instances so both use 127.0.0.1 with different port numbers so that the communicat­ions don’t clash on the same device. When the Multiplaye­r Demonstrat­ion mode isn’t activated, the IP address of the devices is used and each instance has to run on a separate device for the multiplaye­r feature of the game to work. You’ll notice that there are some multiplaye­r settings defined in games.py that refer to IP addresses. self.clientAddr­essPort = ([‘127.0.0.1’, 20002]) self.serverAddr­essPort = ([‘127.0.0.1’, 20001]) self.clientIPAd­dress = self. clientAddr­essPort[0] self.serverIPAd­dress = self. serverAddr­essPort[0] self.clientPort = 20002 self.serverPort = 20001 self.multiplaye­rDemo = False

By default, both client and server IP addresses are set up as the localhost address (127.0.0.1) because at this stage in the program there’s nothing to identify otherwise. An address port variable is also set up for both server and client that contains both the IP address and port number being used.

The port numbers in this example are used to receive communicat­ions. Note that 20001 is to receive data on the server port and port number 20002 is to receive data on the client port.

Newspapers in English

Newspapers from Australia