I would like to implement a TCP Server/client using NDK, can anyone post on example or an ndk project.
i implemented an TCP server but when the client connect gethostbyaddr return NULL any idea
childfd = accept(parentfd, (struct sockaddr *) &clientaddr, &clientlen);
if (childfd < 0)
printf("ERROR on accept");
/*
* gethostbyaddr: determine who sent the message
*/
hostp = gethostbyaddr((const char *)&clientaddr.sin_addr.s_addr,
sizeof(clientaddr.sin_addr.s_addr), AF_INET);
if (hostp == NULL) {
printf("ERROR on gethostbyaddr\n");
return 0;
}
printf("Test1\n");
hostaddrp = inet_ntoa(clientaddr.sin_addr);
if (hostaddrp == NULL)
printf("ERROR on inet_ntoa\n");
printf("server established connection with %s (%s)\n",
hostp->h_name, hostaddrp);
/*
* read: read input string from the client
*/
bzero(buf, BUFSIZE);
n = read(childfd, buf, BUFSIZE);
if (n < 0)
printf("ERROR reading from socket");
printf("server received %d bytes: %s", n, buf);
/*
* write: echo the input string back to the client
*/
n = write(childfd, buf, strlen(buf));
if (n < 0)
printf("ERROR writing to socket");