void AtDrv::startClient(uint8_t sock, uint32_t ipAddress, uint16_t port, uint8_t protMode) { // if we enable CHECK_TCP_STATE feature, always call reConnect(), or we won't get right // tcp port status, since we disable tcp auto reconnect. #ifndef CHECK_TCP_STATE bool needReConn = false; #else bool needReConn = true; #endif int curMode; uint32_t curIp; uint8_t curProtocol; uint16_t curPort; uint16_t curLocalPort; uint32_t curTimeout; bool curTcpAuto; // clear uart buffer first stopClient(sock); if(!isAtMode()) { if(!switchToAtMode()) { INFO1("Can't switch to at mode"); goto end; } } if(!getMode(sock, &curMode) || curMode != MODE_CLIENT) { needReConn = true; INFO1("curMode != MODE_CLIENT"); if(!setMode(sock, MODE_CLIENT)) { INFO1("Can't set mode"); goto end; } } if(!getRemoteIp(sock, (uint8_t *)&curIp) || curIp != ipAddress) { needReConn = true; INFO1("curIp != ipAddress"); if(!setRemoteIp(sock, ipAddress)) { INFO1("Can't set ip"); goto end; } } if(!getProtocol(sock, &curProtocol) || curProtocol != protMode) { needReConn = true; INFO1("curProtocol != protMode"); if(!setProtocol(sock, protMode)) { INFO1("Can't set protocol"); goto end; } } if(!getRemotePort(sock, &curPort) || curPort != port) { needReConn = true; INFO1("curPort != port"); if(!setPort(sock, port)) { INFO1("Can't set port"); goto end; } } if(!getTcpAuto(sock, &curTcpAuto) || curTcpAuto != false) { needReConn = true; INFO1("curTcpAuto != false"); if(!setTcpAuto(sock, false)) { INFO1("Can't set tcp auto"); goto end; } } if(!getLocalPort(sock, &curLocalPort) || curLocalPort != localSockPort[sock]) { needReConn = true; INFO1("curLocalPort != port"); if(!setLocalPort(sock, localSockPort[sock])) { INFO1("Can't set port"); goto end; } } if(needReConn) { if(!reConnect()) { INFO1("Can't reconnect"); goto end; } } sockPort[sock] = localSockPort[sock]; sockConnected[sock] = true; end: return; }
void CxChannelTcpclient::fromContext(const CxIGetSkv& context) { CxChannelBase::fromContext(context); setRemoteIp(context.getValue(CS_EntryRemoteIpAddress, std::string(""))); setRemotePort(context.getValue(CS_EntryRemotePort, 0)); }