Hi!
I'm developing a TCP server running on the nRF9160, but there seem to be a problem with accepting clients. The code is very simple, just calls to socket, bind, listen, accept. But the accept fails as soon as a client tries to connect. ERROR on accept returned -1, errno: 134. I have pasted the code below.
I'm connected to a Cat-M network before I start the server and I have successfully connected from the nRF9160 to another server. But I cannot get the nRF9160 to act as a server. Can you please investigate this?
I'm using:
fw-nrfconnect-nrf tag v1.1.0
Zephyr tag v2.0.99-ncs1
nrfxlib v1.1.0
Modem firmware: 1.1.0
int parentfd; /* parent socket */
int childfd; /* child socket */
int portno; /* port to listen on */
int clientlen; /* byte size of client's address */
struct sockaddr_in serveraddr; /* server's addr */
struct sockaddr_in clientaddr; /* client addr */
portno = 8080;
parentfd = socket(AF_INET, SOCK_STREAM, 0);
if (parentfd < 0) {
LOG_ERR("ERROR opening socket");
return;
}
memset(&serveraddr, 0, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = INADDR_ANY;
serveraddr.sin_port = htons((unsigned short)portno);
if (bind(parentfd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) {
LOG_ERR("ERROR on binding");
return;
}
if (listen(parentfd, 5) < 0) {/* allow 5 requests to queue up */
LOG_ERR("ERROR on listen");
return;
}
while (1) {
LOG_INF("TCP server waiting for client...");
childfd = accept(parentfd, (struct sockaddr *) &clientaddr, &clientlen);
if (childfd < 0) {
LOG_ERR("ERROR on accept returned %d, errno: %d", childfd, errno);
LOG_ERR("Closing server");
close(parentfd);
break;
}
LOG_INF("server established connection");
tcp_handle_client(childfd);
close(childfd);
}
Kind regards
Mattias Eriksson