A communication device, configured to perform communications with one or more devices via a relay server, the communication device comprising a connection managing unit configured to establish, when switching a connection destination from a first relay server serving as an origin to a second relay server serving as a destination, a connection with the second relay server, switch a transmission destination of a message from the first relay server to the second relay server, and cut a connection with the first relay server, wherein
- the connection managing unit transmits an establishment completion notification indicating that establishment of the connection with the second relay server is completed to the first relay server after the connection with the second relay server is established,
- the connection managing unit switches the transmission destination of the message from the first relay server to the second relay server when receiving the establishment completion notification of the one or more devices from the first relay server;
- the message is transmitted together with a value increased by a predetermined increment, and
- the connection managing unit determines, when a second message, having a value increased by the predetermined increment with respect to a maximum value added to a first message already received, is received from the one or more devices, whether the transmission destination of the first message and the transmission destination of the second message are different, and cuts the connection with the first relay server when the transmission destination of the first message and the transmission destination of the second message are different.