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

Developer

Forums

Forums:

I call ISocket_Write after getting a connection. Then I calls ISocket_Read. ISocket_Read returns -2 (AEE_NET_WOULDBLOCK). and when it return AEE_NET_WOULDBLOCK, I delegate to ISocket_Readable, the phone shut down.

samsung x609

void ReadPage(void* p)
{
int i = 0;
MMS_APP* pApp= (MMS_APP*)p;
int rv;
ISocket *piSock =pApp->pISock;
DBGPRINTF("ReadPage");
for (i = 0; i < 1000; i ++)
{
i = i;
}
if(!pApp->pISock)
{
DBGPRINTF("ReadPage error");
for (i = 0; i < 1000; i ++)
{
i = i;
}
pApp->ReadSocketStatus = 2;
return;
}
pApp->ReadSocketStatus = 4;
rv =ISOCKET_Read(piSock,(byte*)pApp->SocketResponse,1024 * 4);
if(rv ==AEE_NET_WOULDBLOCK)
{
if(GETTIMEMS()-pApp->SocketTimems>3000)
{
pApp->ReadSocketStatus = 2; //超时
return;
}
pApp->ReadSocketStatus = 4; //等待
DBGPRINTF("ReadPage 1");
ISOCKET_Readable(piSock,(PFNNOTIFY)ReadPage,pApp);
return;
}
if (rv ==AEE_NET_ERROR || rv==0)
{
pApp->ReadSocketStatus = 2;
return;
}
if(rv >0)
{
DBGPRINTF("ReadPage 2");
for (i = 0; i < 1000; i ++)
{
i = i;
}
pApp->ResponseSize = rv;
pApp->ReadSocketStatus = 1;
pApp->SocketTimems = GETTIMEMS();
MEMMOVE(pApp->m_szCurPage, pApp->SocketResponse, sizeof(pApp->SocketResponse));
CheckResource(pApp);
}

void GetPage(void* p)
{
int i = 0;
MMS_APP* pApp= (MMS_APP*)p;
uint32 writebyte = 0;
int writetime = 0;
boolean writesuccess = FALSE;
unsigned char * szCommand = pApp->m_szSendToServer;
int rv;
if(!pApp->pISock)
{
return ;
}
pApp->ReadSocketStatus = 0;
MEMSET(pApp->SocketResponse, 0, sizeof(pApp->SocketResponse));
while(writetime < 10 && writesuccess != TRUE)
{
writebyte += ISOCKET_Write(pApp->pISock, (byte*)szCommand, pApp->m_nSendToServerLength - writebyte);
if(writebyte == AEE_NET_WOULDBLOCK)
{
writesuccess = FALSE;
writetime++;
}
else if(writebyte == AEE_NET_ERROR || writebyte == 0)
{
}
else if(writebyte > 0)
{
szCommand += writebyte;
if (writebyte >= pApp->m_nSendToServerLength)
{
writesuccess = TRUE;
}
}
}
pApp->SocketTimems = GETTIMEMS();
if(!pApp->pISock)
{
pApp->ReadSocketStatus = 2;
return;
}
pApp->ReadSocketStatus = 4;
rv =ISOCKET_Read(pApp->pISock,(byte*)pApp->SocketResponse,1024 * 4);
if(rv ==AEE_NET_WOULDBLOCK)
{
if(GETTIMEMS()-pApp->SocketTimems>3000)
{
pApp->ReadSocketStatus = 2; //超时
return;
}
pApp->ReadSocketStatus = 4; //等待
ISOCKET_Readable(pApp->pISock,(PFNNOTIFY)ReadPage,pApp);
DBGPRINTF("GetPage 1");
return;
}
if (rv ==AEE_NET_ERROR || rv==0)
{
pApp->ReadSocketStatus = 2;
return;
}
if(rv >0)
{
DBGPRINTF("GetPage 2");
pApp->ResponseSize = rv;
pApp->ReadSocketStatus = 1;
pApp->SocketTimems = GETTIMEMS();
MEMMOVE(pApp->m_szCurPage, pApp->SocketResponse, sizeof(pApp->SocketResponse));
CheckResource(pApp);
}
return ;

void ReadPage(void* p)
{
int i = 0;
MMS_APP* pApp= (MMS_APP*)p;
int rv;
ISocket *piSock =pApp->pISock;
DBGPRINTF("ReadPage");
for (i = 0; i < 1000; i ++)
{
i = i;
}
if(!pApp->pISock)
{
DBGPRINTF("ReadPage error");
for (i = 0; i < 1000; i ++)
{
i = i;
}
pApp->ReadSocketStatus = 2;
return;
}
pApp->ReadSocketStatus = 4;
rv =ISOCKET_Read(piSock,(byte*)pApp->SocketResponse,1024 * 4);
if(rv ==AEE_NET_WOULDBLOCK)
{
if(GETTIMEMS()-pApp->SocketTimems>3000)
{
pApp->ReadSocketStatus = 2; //超时
return;
}
pApp->ReadSocketStatus = 4; //等待
DBGPRINTF("ReadPage 1");
ISOCKET_Readable(piSock,(PFNNOTIFY)ReadPage,pApp);
return;
}
if (rv ==AEE_NET_ERROR || rv==0)
{
pApp->ReadSocketStatus = 2;
return;
}
if(rv >0)
{
DBGPRINTF("ReadPage 2");
for (i = 0; i < 1000; i ++)
{
i = i;
}
pApp->ResponseSize = rv;
pApp->ReadSocketStatus = 1;
pApp->SocketTimems = GETTIMEMS();
MEMMOVE(pApp->m_szCurPage, pApp->SocketResponse, sizeof(pApp->SocketResponse));
CheckResource(pApp);
}

void GetPage(void* p)
{
int i = 0;
MMS_APP* pApp= (MMS_APP*)p;
uint32 writebyte = 0;
int writetime = 0;
boolean writesuccess = FALSE;
unsigned char * szCommand = pApp->m_szSendToServer;
int rv;
if(!pApp->pISock)
{
return ;
}
pApp->ReadSocketStatus = 0;
MEMSET(pApp->SocketResponse, 0, sizeof(pApp->SocketResponse));
while(writetime < 10 && writesuccess != TRUE)
{
writebyte += ISOCKET_Write(pApp->pISock, (byte*)szCommand, pApp->m_nSendToServerLength - writebyte);
if(writebyte == AEE_NET_WOULDBLOCK)
{
writesuccess = FALSE;
writetime++;
}
else if(writebyte == AEE_NET_ERROR || writebyte == 0)
{
}
else if(writebyte > 0)
{
szCommand += writebyte;
if (writebyte >= pApp->m_nSendToServerLength)
{
writesuccess = TRUE;
}
}
}
pApp->SocketTimems = GETTIMEMS();
if(!pApp->pISock)
{
pApp->ReadSocketStatus = 2;
return;
}
pApp->ReadSocketStatus = 4;
rv =ISOCKET_Read(pApp->pISock,(byte*)pApp->SocketResponse,1024 * 4);
if(rv ==AEE_NET_WOULDBLOCK)
{
if(GETTIMEMS()-pApp->SocketTimems>3000)
{
pApp->ReadSocketStatus = 2; //超时
return;
}
pApp->ReadSocketStatus = 4; //等待
ISOCKET_Readable(pApp->pISock,(PFNNOTIFY)ReadPage,pApp);
DBGPRINTF("GetPage 1");
return;
}
if (rv ==AEE_NET_ERROR || rv==0)
{
pApp->ReadSocketStatus = 2;
return;
}
if(rv >0)
{
DBGPRINTF("GetPage 2");
pApp->ResponseSize = rv;
pApp->ReadSocketStatus = 1;
pApp->SocketTimems = GETTIMEMS();
MEMMOVE(pApp->m_szCurPage, pApp->SocketResponse, sizeof(pApp->SocketResponse));
CheckResource(pApp);
}
return ;

hi,
check the connection is getting success or not.
also the AEE_NET_WOULDBLOCK is returned when there is no data to receive.
check the data is send correctly or not.

hi,
check the connection is getting success or not.
also the AEE_NET_WOULDBLOCK is returned when there is no data to receive.
check the data is send correctly or not.

I'm desperately trying to make an ISource from Socket.. But failing to make two sockets talk.. this is the code..
typedef struct _MYAPPDATA
{
AEEApplet m_applet;
IShell* lpShell;
INetMgr* lpInetMngr;
ISocket* lpSocketTx;
ISocket* lpSocketRx;
INAddr lMyIpAddr;
char cBuffer[100];
MYAPPDATA, *LPMYAPPDATA;
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_ISOCKETAPP){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)isocketapp_HandleEvent,NULL)
== TRUE)
{
InitApp((IApplet*)*ppObj);
return (AEE_SUCCESS);
}
}
return (EFAILED);

static boolean isocketapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
StartSocket(pi);
return(TRUE);
case EVT_APP_STOP:
DBGPRINTF("****-Here we go.. App is Ending");
CloseApp(pi);
return TRUE;
}
return FALSE;

static int InitApp(IApplet* lpme)
{
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_NET,(void**)&lpME->lpInetMngr);
return 0;

static void StartSocket(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
INAddr IpAddr;
INPort PortTx,PortRx;
lpME->lpSocketTx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
lpME->lpSocketRx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
iRet = ISOCKET_GetSockName(lpME->lpSocketTx,&IpAddr,&PortTx);
iRet = ISOCKET_GetSockName(lpME->lpSocketRx,&IpAddr,&PortRx);
iRet = ISOCKET_Connect(lpME->lpSocketTx,HTONL(IpAddr),HTONS(PortRx), CallBack,lpme);
iRet = ISOCKET_Write(lpME->lpSocketTx,(byte*)lpME->cBuffer,10);
iRet = INETMGR_GetLastError(lpME->lpInetMngr);
iRet = ISOCKET_Read(lpME->lpSocketRx,(byte*)lpME->cBuffer,10);
iRet = INETMGR_GetLastError(lpME->lpInetMngr);

static void CallBack(void *pconn, int nerror)
{
DBGPRINTF("****--Callback Fn: %d",nerror);

al the calls are succeeding except, ISOCKET_Write and ISOCKET_Read.. I'm getting -1 for those(others are returning 0). But, the IP address when printed usingDBGPRINTF( %d), is printing 66 most of the time, and 19 some times.. Shudnt it be a 32bit value?
In the callsback, I'm getting Error No 557 (0x22D) which means genral failure..
what could be the reaosn of the problem..?
Its so surpricing that BREW help doesnt have any code samples.
Thanks
CoolB

I'm desperately trying to make an ISource from Socket.. But failing to make two sockets talk.. this is the code..
typedef struct _MYAPPDATA
{
AEEApplet m_applet;
IShell* lpShell;
INetMgr* lpInetMngr;
ISocket* lpSocketTx;
ISocket* lpSocketRx;
INAddr lMyIpAddr;
char cBuffer[100];
MYAPPDATA, *LPMYAPPDATA;
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_ISOCKETAPP){
if(AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)isocketapp_HandleEvent,NULL)
== TRUE)
{
InitApp((IApplet*)*ppObj);
return (AEE_SUCCESS);
}
}
return (EFAILED);

static boolean isocketapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
StartSocket(pi);
return(TRUE);
case EVT_APP_STOP:
DBGPRINTF("****-Here we go.. App is Ending");
CloseApp(pi);
return TRUE;
}
return FALSE;

static int InitApp(IApplet* lpme)
{
iRet = ISHELL_CreateInstance(lpME->m_applet.m_pIShell,AEECLSID_NET,(void**)&lpME->lpInetMngr);
return 0;

static void StartSocket(IApplet* lpme)
{
int iRet;
LPMYAPPDATA lpME = (LPMYAPPDATA)lpme;
INAddr IpAddr;
INPort PortTx,PortRx;
lpME->lpSocketTx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
lpME->lpSocketRx = INETMGR_OpenSocket(lpME->lpInetMngr, AEE_SOCK_STREAM);
iRet = ISOCKET_GetSockName(lpME->lpSocketTx,&IpAddr,&PortTx);
iRet = ISOCKET_GetSockName(lpME->lpSocketRx,&IpAddr,&PortRx);
iRet = ISOCKET_Connect(lpME->lpSocketTx,HTONL(IpAddr),HTONS(PortRx), CallBack,lpme);
iRet = ISOCKET_Write(lpME->lpSocketTx,(byte*)lpME->cBuffer,10);
iRet = INETMGR_GetLastError(lpME->lpInetMngr);
iRet = ISOCKET_Read(lpME->lpSocketRx,(byte*)lpME->cBuffer,10);
iRet = INETMGR_GetLastError(lpME->lpInetMngr);

static void CallBack(void *pconn, int nerror)
{
DBGPRINTF("****--Callback Fn: %d",nerror);

al the calls are succeeding except, ISOCKET_Write and ISOCKET_Read.. I'm getting -1 for those(others are returning 0). But, the IP address when printed usingDBGPRINTF( %d), is printing 66 most of the time, and 19 some times.. Shudnt it be a 32bit value?
In the callsback, I'm getting Error No 557 (0x22D) which means genral failure..
what could be the reaosn of the problem..?
Its so surpricing that BREW help doesnt have any code samples.
Thanks
CoolB

hi u have convert 32bit to network byte......
the code to given below is work for me it may help for u

hi u have convert 32bit to network byte......
the code to given below is work for me it may help for u

Hi Gurukumar,
Many thanks for the example app.. Its working perfectly in the Emulator.. But, not in the handset I'm using, Hitachi W42H..probably becauuse it doesnt have any IP protocol configured in it..?
Anyway,my doubt is, is it possible to open two sockets locally in a handset, and then communicate with each other?. We r not connecting to the external work, but, just inside the device. Why I have this strange requirement is, because, I read in some post that we can do Audio streaming using ISource created from a Socket.
Thanks
CoolB

Hi Gurukumar,
Many thanks for the example app.. Its working perfectly in the Emulator.. But, not in the handset I'm using, Hitachi W42H..probably becauuse it doesnt have any IP protocol configured in it..?
Anyway,my doubt is, is it possible to open two sockets locally in a handset, and then communicate with each other?. We r not connecting to the external work, but, just inside the device. Why I have this strange requirement is, because, I read in some post that we can do Audio streaming using ISource created from a Socket.
Thanks
CoolB