求 BREW socket 编程的简单实例

maoyeah 2009-02-06 03:36:33
求 BREW socket 编程的简单实例

给个下载地址,或者把实例直接发至我邮箱:dj8529@sina.com
谢谢!
...全文
3359 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhfan001 2012-06-26
  • 打赏
  • 举报
回复
mark 最近要用到
ayiso 2012-04-26
  • 打赏
  • 举报
回复
模拟器上用本地回环来收发啊
bushibuhuan 2012-03-13
  • 打赏
  • 举报
回复
真是无聊啊!!!!!!!!!!!
kuangyeren_lld 2011-12-29
  • 打赏
  • 举报
回复
现在内外网合并之后直接用连就行了,不用设什么10.0.0.200之类的东西。
ouyangtianke 2011-11-02
  • 打赏
  • 举报
回复
通过socket可以和电脑连接吗?
cjx0084 2010-09-01
  • 打赏
  • 举报
回复
帮顶
回复内容太短了!


windriver2010 2009-12-29
  • 打赏
  • 举报
回复
请教问题,本人采用高通架构遍的程序,但效率非常低,是何原因,百思不得其解,有哪位高手帮忙指点迷津,不胜感激直至。

实现架构:参照高通netdiagnostics.c的实现,读TCP数据时调用ISOCKET_Read,如果当前不可读,则以ISOCKET_Readable设置异步回调函数,在数据到达时再调ISOCKET_Read。

问题:在brew模拟器及6085板子上均出现下载速度慢的问题,表现为ISOCKET_Read每次读取数据约1600字节,但ISOCKET_Readable触发回调函数的间隔时间比较长,使得读数据速度很慢,一般只能达到12k/s
杭州山不高 2009-12-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 maoyeah 的回复:]
回复楼上:
那是HTTP的吧,我要是SOCKET的
[/Quote]
我认为,BREW自带的那个NetDiagnostics,是最好的例子了。
里面既有TCP和UDP的Socket,也有HTTP的例子。
很简单,很清晰了,除了它,找不到更好的了。
freudd 2009-12-08
  • 打赏
  • 举报
回复
自带的那个例子挺好的,多看几次就懂。。。
bencharluo 2009-12-08
  • 打赏
  • 举报
回复
澄清一下,不是不能运行,是我不会用,见笑了
bencharluo 2009-11-22
  • 打赏
  • 举报
回复
不过有很多例子是不能运行的,真够郁闷
ziz2300 2009-07-06
  • 打赏
  • 举报
回复
up!
sunyymq 2009-07-02
  • 打赏
  • 举报
回复
其实自带的那个是最好的例子!说复杂只是你没看明白!
jimhard718 2009-07-01
  • 打赏
  • 举报
回复
static void HelloBrew_Net( ControlTest * pApp)
{
INetMgr *pINetMgr = NULL;
ISocket *pISocket = NULL;
INAddr nodeINAddr;
uint16 nPort;
int netConnect = 0;
//创建一个INetMgr 的实例
if(ISHELL_CreateInstance(pApp->pIShell,AEECLSID_NET,
(void**)&pINetMgr) != SUCCESS)
{
return ;
}
//生成一个ISocket 的实例
pISocket = INETMGR_OpenSocket(pINetMgr,AEE_SOCK_STREAM);
// ip 和端口,其中ip 可以是“#define IP "192.168.0.55"”定义的
nodeINAddr = ConvertToINAddr(IP);
nPort = HTONS(80);
pApp->m_pINetMgr = pINetMgr;
pApp->m_pISocket = pISocket;
//网络连接
if (pISocket)
{
netConnect=
ISOCKET_Connect(pApp->m_pISocket,nodeINAddr,nPort,ConnectCBFun,pApp);
}
ISOCKET_Close(pApp->m_pISocket);
}

INAddr ConvertToINAddr(char* psz)
{
INAddr u1 = 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*)&u1)[nByte++] = n;
if (nByte == 4 || *psz != '.')
{
break;
}
++psz;
}

if (nByte < 4 || isalnum(*psz))
{
u1 = 0xFFFFFFFF;
}

return u1;
}

static void ConnectCBFun(ControlTest* pApp,int wParam)
{
if (wParam != AEE_NET_SUCCESS)
{
int lastError = 1;
char psz[50] = {0};
if (wParam != AEE_NET_WOULDBLOCK)
{
lastError = ISOCKET_GetLastError(pApp->m_pISocket);
if (lastError == AEE_NET_EISCONN)
{
DisplayOutput(pApp,4,"CONNECT FAIL");
DisplayOutput(pApp,3,"The Net Has Connected!");
}
else
{
SPRINTF(psz,"ERROR Number : %d",lastError);
DisplayOutput(pApp,4,"CONNECT FAIL");
}
}
else
{
DisplayOutput(pApp,2,"ERROR:NET_WOULDBLOCK!");
return;
}
}
else
{
DisplayOutput(pApp,4,"CONNECT SUCCESS");
}
}
void DisplayOutput(ControlTest *pApp ,int line,char *pszStr)
{
AECHAR *pszBuf = NULL;
if ((pszBuf = (AECHAR *)MALLOC(200)) == NULL)
{
return;
}
STRTOWSTR((char *)pszStr,pszBuf,200);
IDISPLAY_DrawText(pApp->pIDisplay,AEE_FONT_NORMAL,pszBuf,-1,
0,20*line,NULL,IDF_ALIGN_CENTER);
IDISPLAY_Update(pApp->pIDisplay);
FREEIF(pszBuf);
}
HHunter 2009-05-28
  • 打赏
  • 举报
回复
帮顶
xia56108430 2009-05-14
  • 打赏
  • 举报
回复
实例太难找了!!
CSDN上面好像有些实例吧!!
zsf81 2009-02-17
  • 打赏
  • 举报
回复
楼上这个例子是真机的还是模拟器的?如果是真机的话,我没有看到绑定10.0.0.200?
hhygcy 2009-02-09
  • 打赏
  • 举报
回复
static void Sockapp_Demo(CSocketApp *pme)
{
INetMgr *piNet;
ISocket *piSock;
INAddr nodeINAddr; // IP address in network byte order

//This is a sample function that tries to read from a socket:

xStatus(pme, 0, "Demo");

//Step 1: Create an instance of INetMgr
if (ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_NET, (void**)(&piNet)) != SUCCESS)
{
xStatus(pme, 1, "INetMgr failed");
Sockapp_DemoCleanup(pme);
return; // failed
}
xStatus(pme, 1, "Got INetMgr");

//Set the member into our applet structure
pme->m_piNet = piNet;
INETMGR_SetLinger(pme->m_piNet, 0);

// Step 2: Open the socket. This shall be a TCP socket.
piSock = INETMGR_OpenSocket(piNet, AEE_SOCK_STREAM);
if (!piSock)
{
xStatus(pme, 2, "Socket failed");
Sockapp_DemoCleanup(pme);
return;
}
xStatus(pme, 2, "Got Socket");

//Set the member into our applet structure
pme->m_piSock = piSock;

//Step 3: Connect the Socket
xStatus(pme, 3, "Connecting...");

// Before we can pass on the address to connect the socket, we need to convert the
// address from a string to the INAddr format.
nodeINAddr = xConvertToINAddr(TIMESERVER_HOST);

// Connect the socket. Remember to convert the port number from Host to Network system
// format. This is done using HTONS.
ISOCKET_Connect(piSock, nodeINAddr, HTONS(TIMESERVER_PORT), Sockapp_ConnectCB, pme);
}


/*===========================================================================

FUNCTION Sockapp_ConnectCB()

DESCRIPTION

This function is the callback that accepts the result code from Connect().

It takes a 'void *' so it can be passed to Connect() without a cast.
(Safer to cast a simple structure pointer than to cast a function pointer.)

PARAMETERS:
pme: Pointer to the AEEApplet structure.

===========================================================================*/
static void Sockapp_ConnectCB(void *cxt, int err)
{
CSocketApp *pme = (CSocketApp*)cxt;

if (err)
{
xStatus(pme, 3, "Connect failed!");
Sockapp_DemoCleanup(pme);
return;
}
xStatus(pme, 3, "Connected");

// Success. Socket has been connected. Now read from the Socket.
Sockapp_ReadCB((void*)pme);
}


/*===========================================================================

FUNCTION Sockapp_ReadCB()

DESCRIPTION

This is the function that reads from the socket. It will be called after a
successful connect, and after some data has been read it may schedule itself to
be called again.

It takes a 'void *' so it can be passed to the Readable() without a cast.
(Safer to cast a simple structure pointer than to cast a function pointer.)

PARAMETERS:
pme: Pointer to the AEEApplet structure.

===========================================================================*/
static void Sockapp_ReadCB(void *cxt)
{
CSocketApp *pme = (CSocketApp *)cxt;

ISocket *piSock = pme->m_piSock;
int rv; // Return value frm Read()
uint32 uTime; // Buffer to pass to socket-read function
char szBuf[50];

// Issue a read command on the socket. We know that the address that we have
// connected to returns an uint32 value. Hence, we cast that to char* and send
// it to the read function.

rv = ISOCKET_Read(piSock, (byte*)&uTime, sizeof(uint32));

// Read() return values fall into four categories of interest:
//
// 1. AEE_NET_WOULDBLOCK: This means, data is not yet available on the socket.
// 2. AEE_NET_ERROR: An eror occurred
// 3. 0 (zero): No more data (the peer has closed the connection).
// 3. >0 : The actual data that was read
//

if (rv == AEE_NET_WOULDBLOCK)
{
// WOULDBLOCK => there is no more data available at the moment
//
// In this case, register a callback function using ISOCKET_Readable() and then
// return from this function. The callback will be called by the system at
// a later time. It is perfectly OK to give the current function itself
// as the callback. The callback can then proceed to call ISOCKET_Read()
// to obtain data (or perhaps an error, end of file, etc.).

xStatus(pme, 4, "Waiting...");
ISOCKET_Readable(piSock, Sockapp_ReadCB, (void*)pme);
return;
}
else if (rv == AEE_NET_ERROR)
{
// Connection hosed.
xStatus(pme, 4, "Read Error!");
}
else if (rv > 0) // data has been read
{
SPRINTF(szBuf, "Read: %d", rv);
xStatus(pme, 4, szBuf);

// The data has been read from the socket. So, convert the data from
// host network format to host format.
uTime = NTOHL(uTime) ;

// Display the data.
// This is the time elapsed in seconds since Jan 1 1900.
SPRINTF(szBuf, "Time = %lu", (long) uTime);
xStatus(pme, 5, szBuf);

// If we wanted to read more data, we could loop here or call Readable() here
// and return.
}
else // rv == 0
{
// This demo doesn't expect to see the end of the stream...
xStatus(pme, 4, "No Data!");
}

// Release interfaced used for network activity
Sockapp_DemoCleanup(pme);
}


/*===========================================================================

FUNCTION Sockapp_DemoCleanup()

DESCRIPTION Free any resources allocated as part of the demo. This
can be called before the app exits, or before the demo is repeated.

===========================================================================*/
static void Sockapp_DemoCleanup(CSocketApp *pme)
{
if (pme->m_piSock)
{
ISOCKET_Release(pme->m_piSock);
pme->m_piSock = 0;
}

if (pme->m_piNet)
{
INETMGR_Release(pme->m_piNet);
pme->m_piNet = 0;
}

pme->demoInProgress = FALSE;
}


这是以前高通的sample code
maoyeah 2009-02-09
  • 打赏
  • 举报
回复
如果能有个最简单的socket的就最好,不要多余的代码,那个API本来读起来就很费力,习惯了MFC和C库里的API
  • 打赏
  • 举报
回复
里面既有http,又有socket
加载更多回复(2)

2,854

社区成员

发帖
与我相关
我的任务
社区描述
本论坛以AI、WoS 、XR、IoT、Auto、生成式AI等核心板块组成,为开发者提供便捷及高效的学习和交流平台。 高通开发者专区主页:https://qualcomm.csdn.net/
人工智能物联网机器学习 技术论坛(原bbs) 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧