Socket program with connection 127.0.0.1(Client had connection failure)

Dear.

I just make socket program in legato platform.
It was general example code from web.
Also, It had no problem in ubuntu condition. but when I run same code in legato side
The client could not connect server side and return connection failure.

This is my window legato platform version and example code
(Legato for WP85/WP75 R16.1)

======================================================
Server side code

#define MAX 80
#define PORT 8080
#define SA struct sockaddr

void func(int sockfd)
{
char buff[MAX];
//int n;
// infinite loop for chat
for (;:wink: {
bzero(buff, MAX);
printf("\nserver function call\n");

    // read the message from client and copy it in buffer
    read(sockfd, buff, sizeof(buff));
    // print buffer which contains the client contents
    printf("From client: %s\t To client : ", buff);

    sleep(3);
    strncpy(buff,"Server string",100);
    // and send that buffer to client
    write(sockfd, buff, sizeof(buff));

    // if msg contains "Exit" then server exit and chat ended.
    if (strncmp("exit", buff, 4) == 0) {
        printf("Server Exit...\n");
        break;
    }
}

}

// Driver function
void main()
{
int sockfd, connfd;
socklen_t len;
struct sockaddr_in servaddr, cli;

// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
    printf("socket creation failed...\n");
    exit(0);
}
else
    printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);

// Binding newly created socket to given IP and verification
if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) {
    printf("socket bind failed...\n");
    exit(0);
}
else
    printf("Socket successfully binded..\n");

// Now server is ready to listen and verification
if ((listen(sockfd, 5)) != 0) {
    printf("Listen failed...\n");
    exit(0);
}
else
    printf("Server listening..\n");
len = sizeof(cli);

// Accept the data packet from client and verification
connfd = accept(sockfd, (SA*)&cli, &len);
if (connfd < 0) {
    printf("server acccept failed...\n");
    exit(0);
}
else
    printf("server acccept the client...\n");

// Function for chatting between client and server
func(connfd);

// After chatting close the socket
close(sockfd);

}

==============================================================
Client Side code

#define MAX 80
#define PORT_NO 8080
#define SA struct sockaddr

static int clientSocketFd;
static struct sockaddr_in servaddr;
#define IP_ADDRESS “127.0.0.1” // localhost

void func(int sockfd)
{
char buff[MAX];
//int n;
for (;:wink: {
printf("\nfunc call\n");

	bzero(buff, sizeof(buff));
	strncpy(buff,"client string",100);
	write(sockfd, buff, sizeof(buff));
	
	sleep(3);
	bzero(buff, sizeof(buff));
	read(sockfd, buff, sizeof(buff));
	
	printf("\n");
	printf("From Server : %s", buff);
	if ((strncmp(buff, "exit", 4)) == 0) {
		printf("Client Exit...\n");
		break;
	}
}

}

void main()
{
int sockfd;
struct sockaddr_in servaddr;

// socket create and varification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
	printf("socket creation failed...\n");
	exit(0);
}
else
	printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(PORT_NO);

// connect the client socket to server socket
if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0) {
	printf("connection with the server failed...\n");
	exit(0);
}
else
	printf("connected to the server..\n");

// function for chat
func(sockfd);

// close the socket
close(sockfd);

}

Server side run correctly and never show any error code. but Client side show error return as below

Mar 25 08:41:23 | testserverclient[5937]/testServerClientComponent T=main | testServerClientComponent.c _testServerClientComponent_COMPONENT_INIT() 77 | Client Start
Mar 25 08:41:23 | testserverclient[5937] | | Socket successfully created…
Mar 25 08:41:24 | testserverclient[5937] | | connection with the server failed…

Do you have any tips ?

Thanks all.