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.

TMS320C6678: [TCP]data receive and send via two thread failed

Part Number: TMS320C6678
Other Parts Discussed in Thread: SYSBIOS

Hi Team,

I set 6678 as Server and PC as Client respectively, and the connection between PC and 6678 is good.  

Now, I use one thread to receive data, and it success. I could receive the hello string and the data I sent on PC 

The other one thread is used for sending data, it failed. The message_upload is created on above function server_tcp() by API:   mytask1 = Task_create((ti_sysbios_knl_Task_FuncPtr)message_upload, &mytaskparams1, NULL);

  

But I couldn't receive the "upload:hello" from message_upload function, the return data of send() is -1, while the error is EBADF  9  // Bad file descriptor

Could you offer me some solutions?

Regards

Zahir Wang

  • Hi Zahir wang,

    Sending data from second thread ("message_upload()") will not work because socket descriptor "Socket s" used to create socket for server ("tcp_server()") is not closed. We could not use different file descriptor for same socket.

    If you could use same socket descriptor for both threads kind of like global variable or global "atomic integer" or "semaphore", we can make it work. (Using atomic integer and semaphore, we can restrict the socket descriptor to 1 thread and other thread has to wait till the socket descriptor is free)

    Thanks,

    Rajarajan U

  • Hi Rajarajan

    I added two semaphores to my codes, but it still doesn't work, maybe I didn't use semaphores correctly?

    The latest result is tcp_server could send and receive data, while the message_upload still couldn't send hello to PC.

    I guess the message_upload doesm't get the parameter of "socket s", because the message_upload didn't work when I deleted the code of for loop in tcp_server(). I think the tcp_server get the "socket s" when DaemonNew() executed, while the upload() get the "socket s" from the formal parameter of message_upload(socket s), however, I didn't pass the "socket s" to message_upload() when I use task_create(). 

    Regards

    Zahir Wang

  • Hi Zahir Wang,

    Please make "Socket s" as global and volatile. Then try with semaphore code. The socket descriptor needs to be same variable, if socket re opened for same port with different variable(In your scenario, it is two different local variable). Second thread only returns "-1", since socket is busy and could not be opened.

    Thanks,

    Rajarajan U

  • Hi Rajarajan

    Thanks for your help!

    Instead of using DaemonNew to create a socket, I used socket, bind, listen and accept to get the avaliable and global socket, and then I did it.  

    Regards,

    Zahir Wang

  • Hi Rajarajan

    I use TaskCreate to create socket, and then create the thread of "server_tcp" in connection() via TaskCreate(server_tcp, "server_tcp", OS_TASKPRINORM, OS_TASKSTKNORM, NULL, NULL, NULL); 

     

     After issuing the disconnect API on PC, I try to reconnect. It seems that reconnection is successful from the WIreshark, because three times handshakes success. But I couldn't enter the data send and receive function.

    How can I reenter the server_tcp to send and receive data after reconnection? 

    Regards,

    Zahir Wang

  • I figure out it. I should keep accepting socket, and create the server task when the socket is valiad. In addition, closing the socket is necessary when receiving a disconnect packet.