Socket blocket in read() until disconnection if first received data is lower than 11 bytes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Socket blocket in read() until disconnection if first received data is lower than 11 bytes

sarp
Dear all,

I've created a TCP server using BSD sockets and NUCLEO-H743ZI2 dev kit with
STM32CubeMX & LwIP 2.0.3

I noticed that:
 if a client connects and sends 11 bytes or more at first, server receives
the data correctly; however,
 if the data is lower than 11 bytes, read() function blocks until client
disconnects.
Namely, if incoming data is lower than 11 bytes, event_callback is not
triggered until disconnection.

I've pasted my server task below and uploaded the project to the post(Keil -
STM32CubeMX 5.6.0).
Let me have your kind response at your earliest convenience and feel free to
request related files/flibraries.

Kind Regards
Sarp

void StartTask01(void const * argument)
{
        /* USER CODE BEGIN StartTask01 */
        MX_LWIP_Init();

        /*start a listening tcp server*/
        int iServerSocket;
        struct sockaddr_in address;

        if ((iServerSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        {
                printf("Socket could not be created\n");
        }
        else
        {
                address.sin_family = AF_INET;
                address.sin_port = htons(80);
                address.sin_addr.s_addr = INADDR_ANY;

                if (bind(iServerSocket, (struct sockaddr *)&address, sizeof (address)) <
0)
                {
                        printf("socket could not be bound\n");
                }
                else
                {
                        listen(iServerSocket, MEMP_NUM_NETCONN);
                }
        }
        /*server started listening*/

        for(;;)
        {
                struct sockaddr_in remoteHost;

                /*block until accepting an incoming connection*/
                int newconn = accept(iServerSocket, (struct sockaddr *)&remoteHost,
(socklen_t *)(sizeof(remoteHost)));

                if (newconn != -1)/*if accepted well*/
                {
                        /*block until data arrives*/
                        read(newconn, xTcpConnParams.caRecBuf, sizeof(xTcpConnParams.caRecBuf));
                        printf("data read: %s\n", xTcpConnParams.caRecBuf);
                        memset(xTcpConnParams.caRecBuf, 0, sizeof(xTcpConnParams.caRecBuf));
                }
        }
/* USER CODE END StartTask01 */
}



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Socket blocket in read() until disconnection if first received data is lower than 11 bytes

sarp
SOLVED:

Problem was port specific. Port was 80, I've changed it and thankfully my
rubbish 2 days are justified now.



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Socket blocket in read() until disconnection if first received data is lower than 11 bytes

goldsimon@gmx.de
Am 01.04.2020 um 20:15 schrieb sarp:
> SOLVED:
>
> Problem was port specific. Port was 80, I've changed it and thankfully my
> rubbish 2 days are justified now.

I'm not sure how your problem would depend on the port. But I'm glad you
fixed it.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users