A second terminal device for use in a system that comprises a connection management server, a first terminal device, and the second terminal device, the second terminal device comprising: a control device configured to perform the steps of: obtaining a first local IP address of the first terminal device and first authentication information of the first terminal device from the connection management server in which the first local IP address and the first authentication information are registered, in a case where a first global IP address of the first terminal device matches a second global IP address of the second terminal device; obtaining a set of the first global IP address and a port number of the first terminal device from the connection management server; determining, by use of the obtained first authentication information, whether a first particular terminal device with which the second terminal device can communicate by use of the first local IP address is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and communicating first data with the first terminal device through a LAN by use of the first local IP address, if it is determined that the first particular terminal device is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and communicating second data with the first terminal device through an Internet by use of the set of the first global IP address and the port number if it is determined that the first particular terminal device is not the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device. a control device configured to perform the steps of: obtaining a first local IP address of the first terminal device and first authentication information of the first terminal device from the connection management server in which the first local IP address and the first authentication information are registered, in a case where a first global IP address of the first terminal device matches a second global IP address of the second terminal device; obtaining a set of the first global IP address and a port number of the first terminal device from the connection management server; determining, by use of the obtained first authentication information, whether a first particular terminal device with which the second terminal device can communicate by use of the first local IP address is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and communicating first data with the first terminal device through a LAN by use of the first local IP address, if it is determined that the first particular terminal device is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and obtaining a first local IP address of the first terminal device and first authentication information of the first terminal device from the connection management server in which the first local IP address and the first authentication information are registered, in a case where a first global IP address of the first terminal device matches a second global IP address of the second terminal device; obtaining a set of the first global IP address and a port number of the first terminal device from the connection management server; determining, by use of the obtained first authentication information, whether a first particular terminal device with which the second terminal device can communicate by use of the first local IP address is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and communicating first data with the first terminal device through a LAN by use of the first local IP address, if it is determined that the first particular terminal device is the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device; and communicating second data with the first terminal device through an Internet by use of the set of the first global IP address and the port number if it is determined that the first particular terminal device is not the first terminal device in the case where the first global IP address of the first terminal device matches the second global IP address of the second terminal device.