A method for controlling a second device performed by a first device, the method comprising: detecting, by the first device, an occurrence of a first communication in a first short distance communication mode between the first device and the second device; receiving connection information, which relates to a second short distance communication mode, and identification information, which relates to the second device, the connection information being received from the second device via the first short distance communication mode; automatically determining a computer program stored in the first device for controlling the second device based on the identification information; executing the computer program; establishing (S705-S711) a second communication in the second short distance communication mode between the first device and the second device; and controlling the second device via the second communication by using the computer program, wherein the connection information includes information which indicates whether the second short distance communication mode is a communication mode via a relay, the method further comprising transmitting, to the second device connection information which relates to the relay when the second communication mode is based on a communication which uses the relay, and wherein the connection information that relates to the relay is information which is necessary for implementing a connection to the relay, the method further comprising receiving, from the second device via the first short distance communication mode, a signal which indicates that a communication between the relay and the second device is established in response to receiving the connection information. detecting, by the first device, an occurrence of a first communication in a first short distance communication mode between the first device and the second device; receiving connection information, which relates to a second short distance communication mode, and identification information, which relates to the second device, the connection information being received from the second device via the first short distance communication mode; automatically determining a computer program stored in the first device for controlling the second device based on the identification information; executing the computer program; establishing (S705-S711) a second communication in the second short distance communication mode between the first device and the second device; and controlling the second device via the second communication by using the computer program, wherein the connection information includes information which indicates whether the second short distance communication mode is a communication mode via a relay, the method further comprising transmitting, to the second device connection information which relates to the relay when the second communication mode is based on a communication which uses the relay, and wherein the connection information that relates to the relay is information which is necessary for implementing a connection to the relay, the method further comprising receiving, from the second device via the first short distance communication mode, a signal which indicates that a communication between the relay and the second device is established in response to receiving the connection information.