如果编程人员熟悉Windows平台的SOCKET的使用,那么在DSP平台上一样可以很容易的开发网络应用程序,甚至可以完全不需要了解硬件结构,因为NDK的API和Windows SOCKET API函数名和功能都是十分相近的。下面的程序采用DHCP协议动态获得IP,UDP协议传输数据,如下:
//网络初始化
NC_SystemOpen();
hCfg = CfgNew();
CfgAddEntry( hCfg,CFGTAG_SYSINFO,CFGITEM_DHCP_HOS
TNAME,0,strlen(HostName),(UINT8 *)HostName,0); ……
//配置DHCP协议动态获得IP
CI_SERVICE_DHCPC dhcpc;
bzero(&dhcpc, sizeof(dhcpc));
dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
dhcpc.cisargs.IfIdx = 1;
dhcpc.cisargs.pCbSrv = &ServiceReport;
CfgAddEntry(hCfg,CFGTAG_SERVICE,CFGITEM_SERVICE_D
HCPCLIENT,0,sizeof(dhcpc),(UINT8 *)&dhcpc,0);
……
//配置SOCKET缓冲区大小
rc = 8704;
CfgAddEntry(hCfg,CFGTAG_IP,CFGITEM_IP_SOCKBUFMAX,
CFG_ADDMODE_UNIQUE,sizeof(uint),(UINT8 *)&rc,0);
//启动网络服务
do
{rc = NC_NetStart(hCfg,NetworkOpen,NetworkClose,NetworkIPA
ddr);
} while(rc > 0);
……
//配置应用层协议,本程序采用UDP
SOCKET s;
struct sockaddr_in sin1;
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(bind(s,(PSA) &sin1, sizeof(sin1)) < 0)
|