SENA HD132x Series User Manual
Page 49
HD132x Series User Manual
49
//------------------------------------------------------------------
void TCPSocketClose(int bCloseOnlyClient)
{
//-----------------------------------------------------
// close the client socket
//-----------------------------------------------------
if (sockClient != INVALID_SOCKET) {
closesocket(sockClient);
sockClient = INVALID_SOCKET;
}
if (!bCloseOnlyClient) {
//-----------------------------------------------------
// close the server socket
//-----------------------------------------------------
closesocket(sock);
//-----------------------------------------------------
// terminate use of the WS2_32.DLL
//-----------------------------------------------------
WSACleanup();
}
}
5.2.3 When the HelloDevice is TCP server with a dynamic IP address
This is the case when you want to use the HelloDevice as TCP server in DHCP environment. In DHCP
environment, the HelloDevice has a dynamic IP address, and therefore, the user can't know the IP
address of the HelloDevice because the IP address of the HelloDevice keeps changing.
To solve this problem, the sample program enables users to track the IP information of the
HelloDevice. The HelloDevice includes a function that periodically sends IP information of the
HelloDevice to a data server designated by the user. Therefore, to use the HelloDevice as TCP server
with a dynamic IP address, you should connect to the data server first to obtain the IP address, and
then you can connect to the HelloDevice with the obtained IP address.
In case of WAN, for the HelloDevice to send information, the data server needs to have a public static
IP address. In case of LAN, for the HelloDevice to send information, the data server needs either
public static IP address or private static IP Address
.