Tool/software: TI-RTOS
How to call Task_create with two different ports, i required to simultaneously send/receive from 3 ports with multi task.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI-RTOS
How to call Task_create with two different ports, i required to simultaneously send/receive from 3 ports with multi task.
Hi,
I assume you are talking about multiple "Ethernet" ports based on the other post you are referencing. Is this correct? Did you have a chance to check out the tcpEcho example from TI-RTOS?
Below is the snippet of code in that example that uses the task_create() to create a socket connection. If you have multiple ports I guess you can replicate this task_create() per your application.
In tcpEchoHooks.c
void netOpenHook() { Task_Handle taskHandle; Task_Params taskParams; Error_Block eb; /* Make sure Error_Block is initialized */ Error_init(&eb); /* * Create the Task that farms out incoming TCP connections. * arg0 will be the port that this task listens to. */ Task_Params_init(&taskParams); taskParams.stackSize = TCPHANDLERSTACK; taskParams.priority = 1; taskParams.arg0 = TCPPORT; // TCPPORT is specified in the #define taskHandle = Task_create((Task_FuncPtr)tcpHandler, &taskParams, &eb); if (taskHandle == NULL) { System_printf("netOpenHook: Failed to create tcpHandler Task\n"); }
In tcpEcho.c
Void tcpHandler(UArg arg0, UArg arg1) { int status; int clientfd; int server; struct sockaddr_in localAddr; struct sockaddr_in clientAddr; int optval; int optlen = sizeof(optval); socklen_t addrlen = sizeof(clientAddr); Task_Handle taskHandle; Task_Params taskParams; Error_Block eb; server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (server == -1) { System_printf("Error: socket not created.\n"); goto shutdown; } memset(&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; localAddr.sin_addr.s_addr = htonl(INADDR_ANY); localAddr.sin_port = htons(arg0);
Hi,
Thanks for quick reply.
I need like following code with two different ports, this code compiled successfully but when calling from client the second port getting error "connection is forcefully rejected", first port working fine
Task_Params_init(&taskParams1);
taskParams1.stackSize = TCPHANDLERSTACK;
taskParams1.priority = 1;
taskParams1.arg0 = TCPPORT1;//Ex PORT NUMBER 1000
taskHandle1 = Task_create((Task_FuncPtr)TaskHandler, &taskParams1, &eb1);
if (taskHandle1 == NULL) {
System_printf("netOpenHook #1: Failed to create tcpHandler Task\n");
}
Task_Params_init(&taskParams2);
taskParams2.stackSize = TCPHANDLERSTACK;
taskParams2.priority = 2;
taskParams2.arg0 = TCPPORT2; //Ex PORT NUMBER 1001
taskHandle2 = Task_create((Task_FuncPtr)TaskHandler2, &taskParams2, &eb2);
if (taskHandle2 == NULL) {
System_printf("netOpenHook #2: Failed to create tcpHandler Task\n");
}