Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi all,
From an app running on the phone, I am communicating with an app running on pc through socket programmig.

I donot want to specify the IP address of the pc explicitly.
Is there is a way to get the IP address of the pc,to which the device (phone ) is connected?

Regards,
Sumana.M.H

hi...
if u r using win2000 then open cmd promt and type ipconfig
this will give you ip adr, subnet mask, and gateway addr.
sdg

hi...
if u r using win2000 then open cmd promt and type ipconfig
this will give you ip adr, subnet mask, and gateway addr.
sdg

Hi,
My app on the phone wants the IP address of the computer to which it is connected.
So I want the IP address of the computer using BREW API.
Thank you.

Hi,
My app on the phone wants the IP address of the computer to which it is connected.
So I want the IP address of the computer using BREW API.
Thank you.

Hello Sumana,
If u could have a look at the example INetSocket from Brew1.1,with this app u can get the IP addrs.

Hello Sumana,
If u could have a look at the example INetSocket from Brew1.1,with this app u can get the IP addrs.

The follows may be help:
const char *pszHostIp = "192.168.0.1";
uint32 dwHostIP = Parse(pszHostIp); // see brew sdk 1 example
uint16 wPort = 37;
ISOCKET_Connect
(
pISocket,
dwHostIP,
AEE_htons(wPort),
(PFNCONNECTCB)pfnConnectCB,
(void *)pUser
);
///////////////////////////////////////////////////////
// parse see the example
//
#define ISDIGIT(c) ( (unsigned) ((c) - '0') < 10)
#define ISALPHA(c) ( (unsigned) ( ((c)|32) - 'a') < 26 )
#define ISALNUM(c) ( ISDIGIT(c) || ISALPHA(c) )
static uint32 ConvertToINAddr(char *psz)
{
uint32 ul = 0;
int nByte = 0;
char c;
if(!psz)
return 0;
while (ISDIGIT(*psz)) {
int n = 0;
while ( ISDIGIT(c=*psz)) {
n = n*10 + (c - '0');
++psz;
}
((char*)&ul)[nByte++] = n;
if (nByte == 4 || *psz != '.')
break;
++psz;
}
if (nByte < 4 || ISALNUM(*psz))
ul = 0xFFFFFFFF;
return ul;

The follows may be help:
const char *pszHostIp = "192.168.0.1";
uint32 dwHostIP = Parse(pszHostIp); // see brew sdk 1 example
uint16 wPort = 37;
ISOCKET_Connect
(
pISocket,
dwHostIP,
AEE_htons(wPort),
(PFNCONNECTCB)pfnConnectCB,
(void *)pUser
);
///////////////////////////////////////////////////////
// parse see the example
//
#define ISDIGIT(c) ( (unsigned) ((c) - '0') < 10)
#define ISALPHA(c) ( (unsigned) ( ((c)|32) - 'a') < 26 )
#define ISALNUM(c) ( ISDIGIT(c) || ISALPHA(c) )
static uint32 ConvertToINAddr(char *psz)
{
uint32 ul = 0;
int nByte = 0;
char c;
if(!psz)
return 0;
while (ISDIGIT(*psz)) {
int n = 0;
while ( ISDIGIT(c=*psz)) {
n = n*10 + (c - '0');
++psz;
}
((char*)&ul)[nByte++] = n;
if (nByte == 4 || *psz != '.')
break;
++psz;
}
if (nByte < 4 || ISALNUM(*psz))
ul = 0xFFFFFFFF;
return ul;

you can use the "INetSocket" example as a frame work to get the IP address in runtime.....

you can use the "INetSocket" example as a frame work to get the IP address in runtime.....

Hi all,
if ((iRetValue = ISOCKET_Connect (p->m_pISocket,nodeINAddr, nPort, (PFNCONNECTCB) CommonConnectCB, (void *)p)) != AEE_NET_SUCCESS)
{
if (iRetValue != AEE_NET_WOULDBLOCK)
{
lastError = ISOCKET_GetLastError(p->m_pISocket);
return FALSE;
}
DBGPRINTF("CONNECTION NOT ESTABLISHED");

else
DBGPRINTF("CONNECTION ESTABLISHED");
printing "CONNECTION ESTABLISHED".
But after this it is not calling the callback function specified, on phone.
Where as on emulator callback function is called and message is successfully written on to the socket.
What is the problem?
Thank you ppl.

Hi all,
if ((iRetValue = ISOCKET_Connect (p->m_pISocket,nodeINAddr, nPort, (PFNCONNECTCB) CommonConnectCB, (void *)p)) != AEE_NET_SUCCESS)
{
if (iRetValue != AEE_NET_WOULDBLOCK)
{
lastError = ISOCKET_GetLastError(p->m_pISocket);
return FALSE;
}
DBGPRINTF("CONNECTION NOT ESTABLISHED");

else
DBGPRINTF("CONNECTION ESTABLISHED");
printing "CONNECTION ESTABLISHED".
But after this it is not calling the callback function specified, on phone.
Where as on emulator callback function is called and message is successfully written on to the socket.
What is the problem?
Thank you ppl.

Does your device by chance have BREW 1.1 on it? In that case, failed connections do not timeout; you need to wrap your own timer around ISOCKET_Connect(). Otherwise, your callback is guaranteed to be called eventually.
The common reasons why connections do not complete are:
1) not specifying address and/or port in network byte order
2) trying to connect to a server that is behind a firewall
As to your original question: if your app has called ISOCKET_Connect(), then you have already specified the IP address of the server. Even so, ISOCKET_GetPeerName() will give it back to you after the socket is connected.
Are you really asking how to obtain the address in the first place? If so, perform a DNS query via INETMGR_GetHostByName().

Does your device by chance have BREW 1.1 on it? In that case, failed connections do not timeout; you need to wrap your own timer around ISOCKET_Connect(). Otherwise, your callback is guaranteed to be called eventually.
The common reasons why connections do not complete are:
1) not specifying address and/or port in network byte order
2) trying to connect to a server that is behind a firewall
As to your original question: if your app has called ISOCKET_Connect(), then you have already specified the IP address of the server. Even so, ISOCKET_GetPeerName() will give it back to you after the socket is connected.
Are you really asking how to obtain the address in the first place? If so, perform a DNS query via INETMGR_GetHostByName().