[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Socket blocket in read() until disconnection if first recei
From: |
sarp |
Subject: |
[lwip-users] Socket blocket in read() until disconnection if first received data is lower than 11 bytes |
Date: |
Wed, 1 Apr 2020 06:59:28 -0700 (MST) |
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] Socket blocket in read() until disconnection if first received data is lower than 11 bytes,
sarp <=