lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Doubt-Reg


From: Bellphin Billu
Subject: [lwip-users] Doubt-Reg
Date: Wed, 25 Sep 2013 09:53:54 +0530

Sir,

I configure my program is server and try to establish a connection to single client.initially the communication b/w server and client is good but when you disconnect the port and reconnect it,that time the data communication is not progressed properly.Herewith i attached my TCP server coding.

I humbly ask you to help me.....

int EthConnect()
{
int lSocket;
struct sockaddr_in sLocalAddr;

lSocket = lwip_socket(AF_INET, SOCK_STREAM, 0);
if (lSocket < 0) return;

memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sLocalAddr.sin_port = 5000;

if (lwip_bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
        lwip_close(lSocket);
        return;
}

if ( lwip_listen(lSocket, 20) != 0 ){
        lwip_close(lSocket);
        return;
}

while (1) {
        int clientfd;
        struct sockaddr_in client_addr;
        int addrlen=sizeof(client_addr);
        char buffer[1024];
        int nbytes;

        clientfd = lwip_accept(lSocket, (struct sockaddr*)&client_addr, (socklen_t)&addrlen);
        if (clientfd>0){
            do{
                nbytes=lwip_recv(clientfd, buffer, sizeof(buffer),0);
                if (nbytes>0) lwip_send(clientfd, buffer, nbytes, 0);
            }  while (nbytes>0);

             lwip_close(clientfd);
          }
    } 
    lwip_close(lSocket);
}

Thanks & Reg 
Bellphin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]