freertos, iwip환경하에 UDP통신을 하려는데 포트2개이상은 통신이 안됩니다..
UDP통신을 하려는데 포트1개를 오픈하여 통신하면 통신이 잘되지만 포트를 2개이상 열면 1개만 되고 나머지는 먹통입니다.
코드가 어떤문제가 있는지 지적 부탁 바랍니다..
FOO,BAR모듈 차이점은 포트를 틀리게 오픈하는것밖에없습니다..
lwip옵션중에 UDP PCB갯수를 2개이상 지정해줬는데도 잘안됩니다.
#define MEMP_NUM_UDP_PCB 2
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
//테스크생성하는 모듈(BAR부터 테스크를 생성하면 BAR만 UDP통신이되며 FOO부터 테스크를 생성하면 FOO만 통신됩니다)
sys_thread_new( "BAR", vBasicTFTPServer, ( void * ) NULL,
lwipBASIC_TFTP_SERVER_STACK_SIZE,
lwipBASIC_TFTP_SERVER_PRIORITY );
sys_thread_new( "FOO", TESTFUNC, ( void * ) NULL,
1024, //stack size
lwipBASIC_TFTP_SERVER_PRIORITY+1 ); // task priority
BAR모듈 시작부분
portTASK_FUNCTION( BAR, pvParameters )
{
int lSocket;
int lDataLen, lRecvLen;
socklen_t lFromLen;
struct sockaddr_in sLocalAddr, sFromAddr;
portCHAR cData[SEGSIZE+sizeof(struct tftphdr)];
struct test *sHdr = (struct test *)cData;
// Set up port
// Network order in info; host order in server:
for (;;) {
// Create socket
lSocket = socket(AF_INET, SOCK_DGRAM, 0);
if (lSocket < 0) {
return;
}
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sLocalAddr.sin_port = 1222;
if (bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
// Problem setting up my end
close(lSocket);
return;
}
lRecvLen = sizeof(cData);
lFromLen = sizeof(sFromAddr);
lDataLen = recvfrom(lSocket, sHdr, lRecvLen, 0,
(struct sockaddr *)&sFromAddr, &lFromLen);
close(lSocket); // so that other servers can bind to the socket
if ( lDataLen < 0) {
} else {
printk("emsdata\n");
}
}
FOO모듈 시작부분
portTASK_FUNCTION( FOO, pvParameters )
{
int lSocket;
int lDataLen, lRecvLen;
socklen_t lFromLen;
struct sockaddr_in sLocalAddr, sFromAddr;
portCHAR cData[SEGSIZE+sizeof(struct tftphdr)];
struct test *sHdr = (struct test *)cData;
// Set up port
// Network order in info; host order in server:
for (;;) {
// Create socket
lSocket = socket(AF_INET, SOCK_DGRAM, 0);
if (lSocket < 0) {
return;
}
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sLocalAddr.sin_port = 2000;
if (bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
// Problem setting up my end
close(lSocket);
return;
}
lRecvLen = sizeof(cData);
lFromLen = sizeof(sFromAddr);
lDataLen = recvfrom(lSocket, sHdr, lRecvLen, 0,
(struct sockaddr *)&sFromAddr, &lFromLen);
close(lSocket); // so that other servers can bind to the socket
if ( lDataLen < 0) {
} else {
printk("foo\n");
}
}
댓글 달기