IM kind of functionality in brew | developer.brewmp.com IM kind of functionality in brew | developer.brewmp.com

Developer

IM kind of functionality in brew

Forums:

our project is instant messanger support kind in two or more devices. I think brew has iweb, isocket apis for this?

what should we adopt? also there is confusion in isocket and isockport, they have some simlilar api's. Is something specific to this.

plesae advise.

Thanks,

bob

You can use ISockPort for IM app, Note that ISockport and ISocket have some common API but ISockport is the extended version of ISocket so you would be able to get more features in this interface. ISockPort was introduced after ISocket.

You can use ISockPort for IM app, Note that ISockport and ISocket have some common API but ISockport is the extended version of ISocket so you would be able to get more features in this interface. ISockPort was introduced after ISocket.

Thanks smshesh, can you give some c code of this.
 

Thanks smshesh, can you give some c code of this.
 

Please find below sample code using TCP and UDP cleints.
/***************************************************************************************
FILE: sockports.c
SERVICES: SockPorts applet
DESCRIPTION
This application demonstrates the usage of BREW ISocket
interface.
After starting the application, the user may select from the
following:
1. TCP - the application will open a TCP connection to a server
that
runs an echo service, write a message and expect to read it
back.
2. UDP - the application will send a single packet to a server
that
runs an echo service, and expect to receive an identical
packet.
Copyright (c) 2006 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
===============================================================================
*/
#include "AEEStdLib.h"
#include "AEEModGen.h" // Module interface
definitions
#include "AEEAppGen.h" // Applet interface
definitions
#include "AEEShell.h" // Shell interface
definitions
#include "AEESockPort.h" // SockPort interface
definitions
#include "sockports.bid"
/*-------------------------------------------------------------------
Macro Definitions
-------------------------------------------------------------------*/
#define UDP_MSG_LEN 500
#define TCP_MSG_LEN 5000
#define BUFFER_SIZE MAX(TCP_MSG_LEN,UDP_MSG_LEN)
// We rely on a server that runs an Echo service:
// - If a client sends a UDP packet to server port 7, the server
should
// respond by sending an identical UDP packet to the client.
// - If a client connects in TCP to server port 7, the server
should accept.
// Then, the client may start sending data on this connection,
and the
// server should write this data back to the client.
//
#define ECHO_PORT 7
#define ECHO_SERVER_ADDR "63.160.184.162"
#define RELEASEIF(pi) { if (pi) {
IBASE_Release((IBase*)(pi)); (pi)=0; }}
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via
"pMe->"
-------------------------------------------------------------------*/
typedef struct _CApp {
AEEApplet a ; // First element of this structure
must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the
hardware device information
IDisplay *pIDisplay; // give a standard way to access the
Display interface
IShell *pIShell; // give a standard way to access the
Shell interface
ISockPort* pISockPort;
AEECallback cbCallback;
AEESockAddrStorage saSockAddr;
int nBytesWritten;
int nBytesRead;
char caWriteBuffer[BUFFER_SIZE];
char caReadBuffer[BUFFER_SIZE];
boolean bBusy; // application is busy in
transaction
char szErrMsg[100];
} CApp;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean CApp_HandleEvent(CApp* pMe, AEEEvent eCode,
uint16 wParam, uint32
dwParam);
boolean CApp_InitAppData(CApp* pMe);
void CApp_FreeAppData(CApp* pMe);
static void CApp_Exit(CApp* pMe);
static void CApp_PrintMsg(void* po, const char* str);
static void CApp_StartTCPClient(void* po);
static void CApp_TryConnect(void* po);
static void CApp_TryWrite(void* po);
static void CApp_TryRead(void* po);
static void CApp_StartUDPClient(void* po);
static void CApp_TrySendTo(void* po);
static void CApp_TryRecvFrom(void* po);
/*===============================================================================
FUNCTION DEFINITIONS
===============================================================================
*/
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION:
This function is invoked while the app is being loaded,
and creates the app instance (CApp).
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule
*po, void **ppObj)
{
*ppObj = NULL;
if (ClsId == AEECLSID_SOCKPORTS) {
// Create the applet and make room for the applet
structure.
// the FreeAppData function is called after sending
EVT_APP_STOP
// to the HandleEvent function
if (AEEApplet_New(sizeof(CApp),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)CApp_HandleEvent,
(PFNFREEAPPDATA)CApp_FreeAppData)) {
// Initialize applet data, this is called before sending
EVT_APP_START
// to the HandleEvent function
if(CApp_InitAppData((CApp*)*ppObj)) {
// Data initialized successfully
return(AEE_SUCCESS);
}
else {
// Release the applet. This will free the memory
allocated for the
// applet when AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION: CApp_HandleEvent
DESCRIPTION:
This is the Event Handler for this app. All events to this app
are
handled in this function.
RETURN VALUE
TRUE: the app has processed the event
FALSE: the app did not process the event
===========================================================================*/
static boolean CApp_HandleEvent(CApp* pMe, AEEEvent eCode, uint16
wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
CApp_PrintMsg(pMe, "sockports: 1-TCP, 2-UDP");
return TRUE;
// App is told it is exiting
case EVT_APP_STOP:
return TRUE;
// A key was pressed. Look at the wParam above to see which
key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the
"1" key was pressed.
case EVT_KEY:
if (pMe->bBusy) {
return TRUE;
}
switch(wParam) {
case AVK_1:
CApp_StartTCPClient(pMe);
break;
case AVK_2:
CApp_StartUDPClient(pMe);
break;
default:
return FALSE;
}
return TRUE;
// App does not handle this event
default:
return FALSE;
}
}
/*===========================================================================
FUNCTION: CApp_InitAppData
DESCRIPTION:
Load time initialization of application data.
RETURN VALUE
TRUE: success
FALSE: failure
===========================================================================*/
boolean CApp_InitAppData(CApp* pMe)
{
int i;
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo
structure
// Check the API reference guide for all the handy device info
you can get
pMe->DeviceInfo.wStructSize =
sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
// The display and shell interfaces are always created by
// default, so we'll assign them so that you can access
// them via the standard "pMe->" without the "a."
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
// fill buffer with some text
for (i=0; i < BUFFER_SIZE; ++i) {
pMe->caWriteBuffer[i] = '1' + (i % 10);
}
pMe->saSockAddr.wFamily = AEE_AF_INET;
INET_ATON(ECHO_SERVER_ADDR,
&(pMe->saSockAddr.inet.addr));
pMe->saSockAddr.inet.port = HTONS(ECHO_PORT);
pMe->bBusy = FALSE;
pMe->szErrMsg[0] = 0;
// success
return TRUE;
}
/*===========================================================================
FUNCTION: CApp_FreeAppData
DESCRIPTION:
Free application data upon exit.
===========================================================================*/
void CApp_FreeAppData(CApp* pMe)
{
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
}
/*===========================================================================
TCP Client
----------
The TCP Client opens a connection to an echo server, and sends
some data -
a process which may require sending several packets. Then the TCP
client
waits for the same data to be read back from the echo server.
Typical flow:
CApp_StartTCPClient
-> CApp_TryConnect (may be repeated)
-> CApp_TryWrite (may be repeated)
-> CApp_TryRead (may be repeated)
-> Done
===========================================================================*/
/*===========================================================================
FUNCTION: CApp_StartTCPClient
DESCRIPTION:
Start the TCP client
===========================================================================*/
static void CApp_StartTCPClient(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
pMe->bBusy = TRUE;
CApp_PrintMsg(pMe,"TCP Started");
// some initializations:
STRCPY(pMe->caReadBuffer, "");
pMe->nBytesWritten = 0;
pMe->nBytesRead = 0;
ret = ISHELL_CreateInstance(pMe->pIShell, AEECLSID_SOCKPORT,
(void**)&(pMe->pISockPort));
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "create sockport: %d", ret);
CApp_Exit(pMe);
return;
}
ret = ISOCKPORT_OpenEx(pMe->pISockPort, AEE_AF_INET,
AEE_SOCKPORT_STREAM, 0);
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "openex: %d", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Connecting...");
CApp_TryConnect(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryConnect
DESCRIPTION:
Try connecting to the echo server. if connecting is not
possible at
the moment, we will try again later.
===========================================================================*/
static void CApp_TryConnect(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Connect(pMe->pISockPort,
&pMe->saSockAddr);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback,
CApp_TryConnect, pMe);
return;
}
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "connect error: %d",ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Writing...");
CApp_TryWrite(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryWrite
DESCRIPTION:
Try to write data to the echo server:
- If writing is not possible at the moment, we will try again
later.
- If some data still has to be written, we will continue
later.
===========================================================================*/
static void CApp_TryWrite(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Write(pMe->pISockPort,
pMe->caWriteBuffer +
pMe->nBytesWritten,
TCP_MSG_LEN - pMe->nBytesWritten);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryWrite, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "write: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
pMe->nBytesWritten += ret;
if (pMe->nBytesWritten < TCP_MSG_LEN) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryWrite, pMe);
return;
}
// next step:
CApp_PrintMsg(pMe, "Reading...");
CApp_TryRead(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryRead
DESCRIPTION:
Try to read data from the echo server:
- If reading is not possible at the moment, we will try again
later.
- If some data still has to be read, we will continue
later.
When the reading is complete, we verify that the data read is
as expected,
and release the resources associated with the TCP client.
===========================================================================*/
static void CApp_TryRead(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Read(pMe->pISockPort,
pMe->caReadBuffer +
pMe->nBytesRead,
TCP_MSG_LEN - pMe->nBytesRead);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRead, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "read: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
pMe->nBytesRead += ret;
if (pMe->nBytesRead < TCP_MSG_LEN) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRead, pMe);
return;
}
// just to do something with the data received.
if (0 != MEMCMP(pMe->caReadBuffer, pMe->caWriteBuffer,
TCP_MSG_LEN)) {
SPRINTF(pMe->szErrMsg, "message corrupted");
CApp_Exit(pMe);
return;
}
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
DBGPRINTF("TCP SUCCESS");
CApp_PrintMsg(pMe,"TCP SUCCESS");
pMe->bBusy = FALSE;
}
/*===========================================================================
UDP Client
----------
The UDP Client sends a message to an echo server,
and then it waits for the same message
to be received from the echo server.
Typical flow:
CApp_StartUDPClient
-> CApp_TrySendTo
-> CApp_TryRecvFrom
-> Done
===========================================================================*/
/*===========================================================================
FUNCTION: CApp_StartUDPClient
DESCRIPTION:
Start the UDP client
===========================================================================*/
static void CApp_StartUDPClient(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
pMe->bBusy = TRUE;
CApp_PrintMsg(pMe,"UDP Started");
// some initializations:
STRCPY(pMe->caReadBuffer, "");
pMe->nBytesWritten = 0;
pMe->nBytesRead = 0;
ret = ISHELL_CreateInstance(pMe->pIShell, AEECLSID_SOCKPORT,
(void**)&(pMe->pISockPort));
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "create sockport: %d", ret);
CApp_Exit(pMe);
return;
}
ret = ISOCKPORT_OpenEx(pMe->pISockPort, AEE_AF_INET,
AEE_SOCKPORT_DGRAM, 0);
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "openex: %d", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Sending...");
CApp_TrySendTo(pMe);
}
/*===========================================================================
FUNCTION: CApp_TrySendTo
DESCRIPTION:
Try to send a message to the echo server. If sending is not
possible
at the moment, we will try again later.
===========================================================================*/
static void CApp_TrySendTo(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_SendTo(pMe->pISockPort,
pMe->caWriteBuffer,
UDP_MSG_LEN,
0,
&pMe->saSockAddr);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TrySendTo, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "sendto: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
if (ret < UDP_MSG_LEN) {
SPRINTF(pMe->szErrMsg, "sent only %d bytes", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Receiving...");
CApp_TryRecvFrom(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryRecvFrom
DESCRIPTION:
Try to receive a message from the echo server. If receiving is
not possible
at the moment, we will try again later.
===========================================================================*/
static void CApp_TryRecvFrom(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
AEESockAddrStorage sa;
int nSockAddrSize;
ret = ISOCKPORT_RecvFrom(pMe->pISockPort,
pMe->caReadBuffer,
UDP_MSG_LEN,
0,
&sa,
&nSockAddrSize);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRecvFrom, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "recvfrom: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
if (ret < UDP_MSG_LEN) {
SPRINTF(pMe->szErrMsg, "received only %d bytes",
ret);
CApp_Exit(pMe);
return;
}
// just to do something with the data received.
if (0 != MEMCMP(pMe->caReadBuffer, pMe->caWriteBuffer,
UDP_MSG_LEN)) {
SPRINTF(pMe->szErrMsg, "message corrupted");
CApp_Exit(pMe);
return;
}
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
DBGPRINTF("UDP SUCCESS");
CApp_PrintMsg(pMe,"UDP SUCCESS");
pMe->bBusy = FALSE;
}
/*===========================================================================
FUNCTION: CApp_Stop
DESCRIPTION:
Close the applet. A utility function.
===========================================================================*/
static void CApp_Stop(void* po)
{
CApp* pMe = (CApp*)po;
ISHELL_CloseApplet(pMe->pIShell, FALSE);
}
/*===========================================================================
FUNCTION: CApp_Exit
DESCRIPTION:
Print a message and close the applet. A utility function.
===========================================================================*/
static void CApp_Exit(CApp* pMe)
{
CApp_PrintMsg(pMe, pMe->szErrMsg);
DBGPRINTF(pMe->szErrMsg);
ISHELL_SetTimer(pMe->pIShell, 3000, CApp_Stop, pMe);
}
/*===========================================================================
FUNCTION: CApp_PrintMsg
DESCRIPTION:
Print a message to the screen. A utility function.
===========================================================================*/
void CApp_PrintMsg(void* po, const char* str)
{
CApp* pMe = (CApp*) po;
AECHAR szText[40];
STRTOWSTR(str,szText,sizeof(szText));
IDISPLAY_ClearScreen(pMe->pIDisplay);
IDISPLAY_DrawText(pMe->pIDisplay, AEE_FONT_NORMAL,
szText,
-1, 0, 0, NULL, IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);
IDISPLAY_Update (pMe->pIDisplay);
}
 

Please find below sample code using TCP and UDP cleints.
/***************************************************************************************
FILE: sockports.c
SERVICES: SockPorts applet
DESCRIPTION
This application demonstrates the usage of BREW ISocket
interface.
After starting the application, the user may select from the
following:
1. TCP - the application will open a TCP connection to a server
that
runs an echo service, write a message and expect to read it
back.
2. UDP - the application will send a single packet to a server
that
runs an echo service, and expect to receive an identical
packet.
Copyright (c) 2006 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
===============================================================================
*/
#include "AEEStdLib.h"
#include "AEEModGen.h" // Module interface
definitions
#include "AEEAppGen.h" // Applet interface
definitions
#include "AEEShell.h" // Shell interface
definitions
#include "AEESockPort.h" // SockPort interface
definitions
#include "sockports.bid"
/*-------------------------------------------------------------------
Macro Definitions
-------------------------------------------------------------------*/
#define UDP_MSG_LEN 500
#define TCP_MSG_LEN 5000
#define BUFFER_SIZE MAX(TCP_MSG_LEN,UDP_MSG_LEN)
// We rely on a server that runs an Echo service:
// - If a client sends a UDP packet to server port 7, the server
should
// respond by sending an identical UDP packet to the client.
// - If a client connects in TCP to server port 7, the server
should accept.
// Then, the client may start sending data on this connection,
and the
// server should write this data back to the client.
//
#define ECHO_PORT 7
#define ECHO_SERVER_ADDR "63.160.184.162"
#define RELEASEIF(pi) { if (pi) {
IBASE_Release((IBase*)(pi)); (pi)=0; }}
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via
"pMe->"
-------------------------------------------------------------------*/
typedef struct _CApp {
AEEApplet a ; // First element of this structure
must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the
hardware device information
IDisplay *pIDisplay; // give a standard way to access the
Display interface
IShell *pIShell; // give a standard way to access the
Shell interface
ISockPort* pISockPort;
AEECallback cbCallback;
AEESockAddrStorage saSockAddr;
int nBytesWritten;
int nBytesRead;
char caWriteBuffer[BUFFER_SIZE];
char caReadBuffer[BUFFER_SIZE];
boolean bBusy; // application is busy in
transaction
char szErrMsg[100];
} CApp;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean CApp_HandleEvent(CApp* pMe, AEEEvent eCode,
uint16 wParam, uint32
dwParam);
boolean CApp_InitAppData(CApp* pMe);
void CApp_FreeAppData(CApp* pMe);
static void CApp_Exit(CApp* pMe);
static void CApp_PrintMsg(void* po, const char* str);
static void CApp_StartTCPClient(void* po);
static void CApp_TryConnect(void* po);
static void CApp_TryWrite(void* po);
static void CApp_TryRead(void* po);
static void CApp_StartUDPClient(void* po);
static void CApp_TrySendTo(void* po);
static void CApp_TryRecvFrom(void* po);
/*===============================================================================
FUNCTION DEFINITIONS
===============================================================================
*/
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION:
This function is invoked while the app is being loaded,
and creates the app instance (CApp).
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule
*po, void **ppObj)
{
*ppObj = NULL;
if (ClsId == AEECLSID_SOCKPORTS) {
// Create the applet and make room for the applet
structure.
// the FreeAppData function is called after sending
EVT_APP_STOP
// to the HandleEvent function
if (AEEApplet_New(sizeof(CApp),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)CApp_HandleEvent,
(PFNFREEAPPDATA)CApp_FreeAppData)) {
// Initialize applet data, this is called before sending
EVT_APP_START
// to the HandleEvent function
if(CApp_InitAppData((CApp*)*ppObj)) {
// Data initialized successfully
return(AEE_SUCCESS);
}
else {
// Release the applet. This will free the memory
allocated for the
// applet when AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION: CApp_HandleEvent
DESCRIPTION:
This is the Event Handler for this app. All events to this app
are
handled in this function.
RETURN VALUE
TRUE: the app has processed the event
FALSE: the app did not process the event
===========================================================================*/
static boolean CApp_HandleEvent(CApp* pMe, AEEEvent eCode, uint16
wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
CApp_PrintMsg(pMe, "sockports: 1-TCP, 2-UDP");
return TRUE;
// App is told it is exiting
case EVT_APP_STOP:
return TRUE;
// A key was pressed. Look at the wParam above to see which
key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the
"1" key was pressed.
case EVT_KEY:
if (pMe->bBusy) {
return TRUE;
}
switch(wParam) {
case AVK_1:
CApp_StartTCPClient(pMe);
break;
case AVK_2:
CApp_StartUDPClient(pMe);
break;
default:
return FALSE;
}
return TRUE;
// App does not handle this event
default:
return FALSE;
}
}
/*===========================================================================
FUNCTION: CApp_InitAppData
DESCRIPTION:
Load time initialization of application data.
RETURN VALUE
TRUE: success
FALSE: failure
===========================================================================*/
boolean CApp_InitAppData(CApp* pMe)
{
int i;
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo
structure
// Check the API reference guide for all the handy device info
you can get
pMe->DeviceInfo.wStructSize =
sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
// The display and shell interfaces are always created by
// default, so we'll assign them so that you can access
// them via the standard "pMe->" without the "a."
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
// fill buffer with some text
for (i=0; i < BUFFER_SIZE; ++i) {
pMe->caWriteBuffer[i] = '1' + (i % 10);
}
pMe->saSockAddr.wFamily = AEE_AF_INET;
INET_ATON(ECHO_SERVER_ADDR,
&(pMe->saSockAddr.inet.addr));
pMe->saSockAddr.inet.port = HTONS(ECHO_PORT);
pMe->bBusy = FALSE;
pMe->szErrMsg[0] = 0;
// success
return TRUE;
}
/*===========================================================================
FUNCTION: CApp_FreeAppData
DESCRIPTION:
Free application data upon exit.
===========================================================================*/
void CApp_FreeAppData(CApp* pMe)
{
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
}
/*===========================================================================
TCP Client
----------
The TCP Client opens a connection to an echo server, and sends
some data -
a process which may require sending several packets. Then the TCP
client
waits for the same data to be read back from the echo server.
Typical flow:
CApp_StartTCPClient
-> CApp_TryConnect (may be repeated)
-> CApp_TryWrite (may be repeated)
-> CApp_TryRead (may be repeated)
-> Done
===========================================================================*/
/*===========================================================================
FUNCTION: CApp_StartTCPClient
DESCRIPTION:
Start the TCP client
===========================================================================*/
static void CApp_StartTCPClient(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
pMe->bBusy = TRUE;
CApp_PrintMsg(pMe,"TCP Started");
// some initializations:
STRCPY(pMe->caReadBuffer, "");
pMe->nBytesWritten = 0;
pMe->nBytesRead = 0;
ret = ISHELL_CreateInstance(pMe->pIShell, AEECLSID_SOCKPORT,
(void**)&(pMe->pISockPort));
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "create sockport: %d", ret);
CApp_Exit(pMe);
return;
}
ret = ISOCKPORT_OpenEx(pMe->pISockPort, AEE_AF_INET,
AEE_SOCKPORT_STREAM, 0);
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "openex: %d", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Connecting...");
CApp_TryConnect(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryConnect
DESCRIPTION:
Try connecting to the echo server. if connecting is not
possible at
the moment, we will try again later.
===========================================================================*/
static void CApp_TryConnect(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Connect(pMe->pISockPort,
&pMe->saSockAddr);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback,
CApp_TryConnect, pMe);
return;
}
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "connect error: %d",ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Writing...");
CApp_TryWrite(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryWrite
DESCRIPTION:
Try to write data to the echo server:
- If writing is not possible at the moment, we will try again
later.
- If some data still has to be written, we will continue
later.
===========================================================================*/
static void CApp_TryWrite(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Write(pMe->pISockPort,
pMe->caWriteBuffer +
pMe->nBytesWritten,
TCP_MSG_LEN - pMe->nBytesWritten);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryWrite, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "write: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
pMe->nBytesWritten += ret;
if (pMe->nBytesWritten < TCP_MSG_LEN) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryWrite, pMe);
return;
}
// next step:
CApp_PrintMsg(pMe, "Reading...");
CApp_TryRead(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryRead
DESCRIPTION:
Try to read data from the echo server:
- If reading is not possible at the moment, we will try again
later.
- If some data still has to be read, we will continue
later.
When the reading is complete, we verify that the data read is
as expected,
and release the resources associated with the TCP client.
===========================================================================*/
static void CApp_TryRead(void* po)
{
CApp *pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_Read(pMe->pISockPort,
pMe->caReadBuffer +
pMe->nBytesRead,
TCP_MSG_LEN - pMe->nBytesRead);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRead, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "read: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
pMe->nBytesRead += ret;
if (pMe->nBytesRead < TCP_MSG_LEN) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRead, pMe);
return;
}
// just to do something with the data received.
if (0 != MEMCMP(pMe->caReadBuffer, pMe->caWriteBuffer,
TCP_MSG_LEN)) {
SPRINTF(pMe->szErrMsg, "message corrupted");
CApp_Exit(pMe);
return;
}
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
DBGPRINTF("TCP SUCCESS");
CApp_PrintMsg(pMe,"TCP SUCCESS");
pMe->bBusy = FALSE;
}
/*===========================================================================
UDP Client
----------
The UDP Client sends a message to an echo server,
and then it waits for the same message
to be received from the echo server.
Typical flow:
CApp_StartUDPClient
-> CApp_TrySendTo
-> CApp_TryRecvFrom
-> Done
===========================================================================*/
/*===========================================================================
FUNCTION: CApp_StartUDPClient
DESCRIPTION:
Start the UDP client
===========================================================================*/
static void CApp_StartUDPClient(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
pMe->bBusy = TRUE;
CApp_PrintMsg(pMe,"UDP Started");
// some initializations:
STRCPY(pMe->caReadBuffer, "");
pMe->nBytesWritten = 0;
pMe->nBytesRead = 0;
ret = ISHELL_CreateInstance(pMe->pIShell, AEECLSID_SOCKPORT,
(void**)&(pMe->pISockPort));
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "create sockport: %d", ret);
CApp_Exit(pMe);
return;
}
ret = ISOCKPORT_OpenEx(pMe->pISockPort, AEE_AF_INET,
AEE_SOCKPORT_DGRAM, 0);
if (SUCCESS != ret) {
SPRINTF(pMe->szErrMsg, "openex: %d", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Sending...");
CApp_TrySendTo(pMe);
}
/*===========================================================================
FUNCTION: CApp_TrySendTo
DESCRIPTION:
Try to send a message to the echo server. If sending is not
possible
at the moment, we will try again later.
===========================================================================*/
static void CApp_TrySendTo(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
ret = ISOCKPORT_SendTo(pMe->pISockPort,
pMe->caWriteBuffer,
UDP_MSG_LEN,
0,
&pMe->saSockAddr);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_WriteableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TrySendTo, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "sendto: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
if (ret < UDP_MSG_LEN) {
SPRINTF(pMe->szErrMsg, "sent only %d bytes", ret);
CApp_Exit(pMe);
return;
}
// next step:
CApp_PrintMsg(pMe,"Receiving...");
CApp_TryRecvFrom(pMe);
}
/*===========================================================================
FUNCTION: CApp_TryRecvFrom
DESCRIPTION:
Try to receive a message from the echo server. If receiving is
not possible
at the moment, we will try again later.
===========================================================================*/
static void CApp_TryRecvFrom(void* po)
{
CApp * pMe = (CApp*)po;
int ret;
AEESockAddrStorage sa;
int nSockAddrSize;
ret = ISOCKPORT_RecvFrom(pMe->pISockPort,
pMe->caReadBuffer,
UDP_MSG_LEN,
0,
&sa,
&nSockAddrSize);
if (AEEPORT_WAIT == ret) {
ISOCKPORT_ReadableEx(pMe->pISockPort,
&pMe->cbCallback, CApp_TryRecvFrom, pMe);
return;
}
if (AEEPORT_ERROR == ret) {
SPRINTF(pMe->szErrMsg, "recvfrom: %d",
ISOCKPORT_GetLastError(pMe->pISockPort));
CApp_Exit(pMe);
return;
}
if (ret < UDP_MSG_LEN) {
SPRINTF(pMe->szErrMsg, "received only %d bytes",
ret);
CApp_Exit(pMe);
return;
}
// just to do something with the data received.
if (0 != MEMCMP(pMe->caReadBuffer, pMe->caWriteBuffer,
UDP_MSG_LEN)) {
SPRINTF(pMe->szErrMsg, "message corrupted");
CApp_Exit(pMe);
return;
}
CALLBACK_Cancel(&(pMe->cbCallback));
RELEASEIF(pMe->pISockPort);
DBGPRINTF("UDP SUCCESS");
CApp_PrintMsg(pMe,"UDP SUCCESS");
pMe->bBusy = FALSE;
}
/*===========================================================================
FUNCTION: CApp_Stop
DESCRIPTION:
Close the applet. A utility function.
===========================================================================*/
static void CApp_Stop(void* po)
{
CApp* pMe = (CApp*)po;
ISHELL_CloseApplet(pMe->pIShell, FALSE);
}
/*===========================================================================
FUNCTION: CApp_Exit
DESCRIPTION:
Print a message and close the applet. A utility function.
===========================================================================*/
static void CApp_Exit(CApp* pMe)
{
CApp_PrintMsg(pMe, pMe->szErrMsg);
DBGPRINTF(pMe->szErrMsg);
ISHELL_SetTimer(pMe->pIShell, 3000, CApp_Stop, pMe);
}
/*===========================================================================
FUNCTION: CApp_PrintMsg
DESCRIPTION:
Print a message to the screen. A utility function.
===========================================================================*/
void CApp_PrintMsg(void* po, const char* str)
{
CApp* pMe = (CApp*) po;
AECHAR szText[40];
STRTOWSTR(str,szText,sizeof(szText));
IDISPLAY_ClearScreen(pMe->pIDisplay);
IDISPLAY_DrawText(pMe->pIDisplay, AEE_FONT_NORMAL,
szText,
-1, 0, 0, NULL, IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);
IDISPLAY_Update (pMe->pIDisplay);
}
 

Thanks smahesh, I am trying to implement Isockport in my application but on compilation i am getting linker errors of isockport api's?

Thanks smahesh, I am trying to implement Isockport in my application but on compilation i am getting linker errors of isockport api's?

did you include header file isockport.h in your application? You may have missed this, including this will solve the problem.

did you include header file isockport.h in your application? You may have missed this, including this will solve the problem.

Thanks, its working now. I have another problem/issue with storing sms.
ISMSSTORAGE_EnumNextMsg(pMe->m_pISMSStorage, pMe->SmsStoreType, &pMe->EnumMsgCb,&pMe->m_dwMsgIndexInBox, &pMe->m_pISMSMsg, &pMe->m_dwMsgStatus);
for CDMA devices :
should i use AEESMS_NV_CDMA? or AEESMS_CARD_RUIM? I am confused becuase some devices have RUIM and some not, please guide me. 

Thanks, its working now. I have another problem/issue with storing sms.
ISMSSTORAGE_EnumNextMsg(pMe->m_pISMSStorage, pMe->SmsStoreType, &pMe->EnumMsgCb,&pMe->m_dwMsgIndexInBox, &pMe->m_pISMSMsg, &pMe->m_dwMsgStatus);
for CDMA devices :
should i use AEESMS_NV_CDMA? or AEESMS_CARD_RUIM? I am confused becuase some devices have RUIM and some not, please guide me.