本帖最后由 ccjgalaxy 于 2009-9-4 10:14 编辑
我就是想把rxda[6]中的数据{1,2,2,3,4,5}在接收窗口中显示出来
难道NDK网络通信也需要有中断触发吗?
要不然为什么我运行程序时,我在程序中想要发送的 1,2,2,3,4,5 不能直接发送到数据接收窗口呢?
void tskNetworkTx()
{
SOCKET slisten = INVALID_SOCKET;
struct sockaddr_in sin1;
SCOM_Handle hs_Netok;
int hr,Tmp, rxlen;
unsigned char rxda[6]={1,2,2,3,4,5};
unsigned char *Databuf;
/*打开SCOM模块*/
hs_Netok = SCOM_open("NETOK");
if( !hs_Netok )
{
for(;;);
}
// 等待所有的初始化完成
TSK_sleep(500);
SCOM_getMsg( hs_Netok, SYS_FOREVER );
// Allocate the file environment for this task
fdOpenSession( TaskSelf() );
// Create the main TCP listen socket
slisten = socket(AF_INET, SOCK_STREAMNC, IPPROTO_TCP);
if( slisten == INVALID_SOCKET )
{
goto leave;
}
// Set Port = 2000, leaving IP address = Any
bzero( &sin1, sizeof(struct sockaddr_in) );
sin1.sin_family = AF_INET;
sin1.sin_len = sizeof( sin1 );
sin1.sin_addr.s_addr = inet_addr(ServerPAddr);
sin1.sin_port = htons(5150);//网络端口
//如果没有网络连接就直接跳出
if (linkstatus==0)
{
goto leave;
}
xx: if( connect( slisten, (PSA) &sin1, sizeof(sin1) ) == SOCKET_ERROR )
{
printf("Connect failed (%d)\n",fdError());
goto leave;
}
// 如果是网络错误,重新连接网络;如果是传输数据头错误,丢一帧继续传输
for(;;)
{
// Send received data back to host
Databuf = rxda;
rxlen=6;
while(rxlen > 0)
{
Tmp = send(slisten, Databuf, rxlen, 0);
if (Tmp == rxlen)
break;
if ((Tmp == SOCKET_ERROR)||(Tmp == -1))
{
printf("network failed!");
goto xx;
}
// If partional data transfered, then continue transfer
rxlen -= Tmp;
Databuf += Tmp;
}
if(hr == SOCKET_ERROR)
goto xx;
}
leave:
// We only get here on a fatal error - close the sockets
if( slisten != INVALID_SOCKET )
{
fdClose( slisten );
}
printf("tskNetwork Fatal Error\n");
// This task is killed by the system - here, we block
TaskBlock( TaskSelf() );
} |