Tool/software: Code Composer Studio
I have a CC3200 connecting via P2P to an Android phone with the Android as the Group Owner. The CC3200 sends a UDP packet on a prefixed port (8080) from which the Android retrieves its IP and dynamically generated port number. The Android stores that information and all future communication with the CC320 occurs over the dynamically generated port.
My problem is with finding the dynamically generated port on the CC3200. How do I extract it from the socket and save it to a variable?
My code is from the udp_socket example (slightly modified) as follows.
int UdpSendSocket(unsigned short usPort)
{
SlSockAddrIn_t sAddr;
int iCounter;
int iAddrSize;
int iSockID;
int iStatus;
short sBufLen;
// filling the buffer
for (iCounter=0 ; iCounter < strlen(g_cAck) ; iCounter++)
{
g_cBsdBuf[iCounter] = (char)(g_cAck[iCounter]);
}
//sTestBufLen = BUF_SIZE; //original code
//set buffer length to size of message
sBufLen = strlen(g_cAck);
//filling the UDP server socket address
sAddr.sin_family = SL_AF_INET;
sAddr.sin_port = sl_Htons((unsigned short)usPort); //rearranges order of bytes for port
sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulGatewayIp); //rearranges order of bytes for IP
iAddrSize = sizeof(SlSockAddrIn_t);
// creating a UDP socket
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
if( iSockID < 0 )
{
// error
ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
}
// for a UDP connection connect is not required
// sending packet
iStatus = sl_SendTo(iSockID, g_cBsdBuf, sBufLen, 0,
(SlSockAddr_t *)&sAddr, iAddrSize);
if( iStatus <= 0 )
{
// error
sl_Close(iSockID);
ASSERT_ON_ERROR(SEND_ERROR);
}
UART_PRINT("Sent %u packets successfully\n\r", g_ulPacketCount);
//closing the socket after sending 1 packet
sl_Close(iSockID);
return SUCCESS;
}