[lwip-users] Checking whether the client is connected to the Server

874 views
Skip to first unread message

Teckinal Greek

unread,
Aug 27, 2010, 7:56:50 AM8/27/10
to lwip
Hi, 
I am working on establishing Client-Server module over TCP.I have put a set up such that my PC acts as a normal server where I can connect it from some other PC's on my LAN using 'telnet ipaddress port' command and once I get connected with the server and can give some input from client computer so that it gets displayed on my server window(connection is established and data exchange takes place). 
Until here I can say that the server is working fine and what i wanted to implement is that now I wrote a code using lwIP API for the Altium Nanaboard so that my NB3000 acts like a client and i wanted it to get connected to my PC Server. 
Here goes my code for the client part which gets connected to the Server with given IPaddress. 

int tcp_client(void) 

char data[] = "Hello World"; 
struct netconn *conn; 
struct ip_addr ServAddr; 
err_t err; 
u16_t port; 

port = 7777; 

conn = netconn_new(NETCONN_TCP); 

IP4_ADDR(&ServAddr, 192,168,xx,xxx); 

err = netconn_connect(conn, &ServAddr, port); 

printf("err = %d", err); //err = -4 this is the value I am getting for err.

if(err == ERR_OK) 

netconn_write(conn, data, sizeof(data), NETCONN_NOCOPY); 

netconn_close(conn); 

netconn_delete(conn); 



here i open a new connection and connect it to Server using its IPaddress. 

Before that I wanted to check the connection whether it is connected or not, so what i did is i assigned a variable "err" and when I try to print it out on the terminal instrument and see the value it gives a value of "-4". 
Is this correct what I am doing here so that if i get a negative value that means the client is successfully connected to the server. 
If so how can i transfer the data "Hello World" on to my server and get it displayed there. 
Kind Regards,
Greek

Kieran Mansley

unread,
Aug 27, 2010, 8:18:03 AM8/27/10
to Mailing list for lwIP users
On Fri, 2010-08-27 at 11:56 +0000, Teckinal Greek wrote:
> Before that I wanted to check the connection whether it is connected
> or not, so what i did is i assigned a variable "err" and when I try to
> print it out on the terminal instrument and see the value it gives a
> value of "-4".

That means there is no route from the client to the host. How are you
configuring the netif?

Kieran


_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
http://lists.nongnu.org/mailman/listinfo/lwip-users

Teckinal Greek

unread,
Aug 27, 2010, 9:28:55 AM8/27/10
to lwip
Hi Kieran,
thanks for your reply :-)

This is how I am configuring netif

struct netif netif;

void lwip_setup(void)
{
    sys_sem_t init_sem;
    struct netif *netif;

    printf("Starting lwIP\n");

    // init tcpip thread and wait for it to finish booting.
    init_sem = sys_sem_new(0);

    tcpip_init(tcpip_init_done, init_sem);

    sys_sem_wait(init_sem);
    sys_sem_free(init_sem);

    netif = netif_ethernet_open(LWIP_1);

    netif_set_default(netif);

}

I think this part is fine, only I could not able to connect to the server. Feel free to ask any information you want.

Thanks and Regards,
Greek

> Subject: Re: [lwip-users] Checking whether the client is connected to the Server
> From: kie...@recoil.org
> To: lwip-...@nongnu.org
> Date: Fri, 27 Aug 2010 13:18:03 +0100

Kieran Mansley

unread,
Aug 27, 2010, 9:35:38 AM8/27/10
to Mailing list for lwIP users
On Fri, 2010-08-27 at 13:28 +0000, Teckinal Greek wrote:
> netif = netif_ethernet_open(LWIP_1);

What does this function do?

Teckinal Greek

unread,
Aug 30, 2010, 5:26:38 AM8/30/10
to lwip
Hi Kieran,
netif = netif_ethernet_open(LWIP_1) - this function opens the Ethernet connection on my FPGA board which is called Altium Nanoboard 3000.Also this function uses the TCP/IP Networking context whose ID is LWIP_1 this is set in my Software Platform of my project. I am enclosing a screen shot of how I configured this Software platform for my project.
Regards,
Greek

> Subject: RE: [lwip-users] Checking whether the client is connected to the Server
> From: kie...@recoil.org
> To: lwip-...@nongnu.org
> Date: Fri, 27 Aug 2010 14:35:38 +0100

Kieran Mansley

unread,
Aug 31, 2010, 4:09:41 AM8/31/10
to Mailing list for lwIP users
On Mon, 2010-08-30 at 09:26 +0000, Teckinal Greek wrote:
> Hi Kieran,netif = netif_ethernet_open(LWIP_1) - this function opens

> the Ethernet connection on my FPGA board which is called Altium
> Nanoboard 3000.Also this function uses the TCP/IP Networking context
> whose ID is LWIP_1 this is set in my Software Platform of my project.
> I am enclosing a screen shot of how I configured this Software
> platform for my project.Regards,Greek

Could you show us the source for that function?

Teckinal Greek

unread,
Aug 31, 2010, 6:21:12 AM8/31/10
to lwip



    Hi,
yesterday i forgot to attach the screen shot of how i configured this Software platform for my project, now I am resending it with the attachment. Hope that explains or else let me know! In the mean time I have switched over to lwIP RAW API and ported the code. Now what i can see is that the value of err = 0 in the below statement 

err = tcp_connect(pcb, &ServAddr, 7777, client_connected); 

and at the same time in the conditional statement  if(err == ERR_OK) is satisfied that means I got connected to my server.

But the problem arises with writing to the server with this block

static err_t client_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
    char string[] = "Hello!";
    LWIP_UNUSED_ARG(arg);

    if(err != ERR_OK)
    printf("\n client connected(): err argument not set to ERR_OK, but the value is %d\n", err);
    else
    {
         printf("\n client connected \n");
        tcp_sent(pcb, client_sent);
        tcp_write(pcb, string, sizeof(string), 0);
    }
    return err;
}

where I have asked the client to sending the string "Hello!" to the server. If it is sending to the server how can i find out that it is sending the data.

Please feel free to ask any more information you need in this case, since I am a newbie I may not have understood your previous questions correctly.

Regards,
Greek.



> Subject: RE: [lwip-users] Checking whether the client is connected to the Server
> From: kie...@recoil.org
> To: lwip-...@nongnu.org
> Date: Tue, 31 Aug 2010 09:09:41 +0100

Kieran Mansley

unread,
Aug 31, 2010, 6:28:39 AM8/31/10
to Mailing list for lwIP users
On Tue, 2010-08-31 at 10:21 +0000, Teckinal Greek wrote:
>
>
>
> ______________________________________________________________________

> Hi,
> yesterday i forgot to attach the screen shot of how i configured this
> Software platform for my project, now I am resending it with
> the attachment. Hope that explains or else let me know! In the mean
> time I have switched over to lwIP RAW API and ported the code. Now
> what i can see is that the value of err = 0 in the below statement
>
>
> err = tcp_connect(pcb, &ServAddr, 7777, client_connected);
>
>
> and at the same time in the conditional statement if(err == ERR_OK)
> is satisfied that means I got connected to my server.

You said earlier that you were getting an ERR_RTE when trying to
connect. Are you now saying that you don't get this error when trying
to connect and tcp_connect is returning ERR_OK? If you're still seeing
a routing error at connection time it would be useful to see the source
to your netif_ethernet_open() function

> But the problem arises with writing to the server with this block
>
>
> static err_t client_connected(void *arg, struct tcp_pcb *pcb, err_t
> err)
> {
> char string[] = "Hello!";
> LWIP_UNUSED_ARG(arg);
>
>
> if(err != ERR_OK)
> printf("\n client connected(): err argument not set to ERR_OK, but
> the value is %d\n", err);
> else
> {
> printf("\n client connected \n");
> tcp_sent(pcb, client_sent);
> tcp_write(pcb, string, sizeof(string), 0);
> }
> return err;
> }
>
>
> where I have asked the client to sending the string "Hello!" to the
> server. If it is sending to the server how can i find out that it is
> sending the data.

Look at the return value of tcp_write() and wait for your client_sent
function to be called.

Kieran Mansley

unread,
Aug 31, 2010, 6:36:00 AM8/31/10
to Mailing list for lwIP users
On Tue, 2010-08-31 at 11:28 +0100, Kieran Mansley wrote:
>
> Look at the return value of tcp_write() and wait for your client_sent
> function to be called.

Also if you want data to be sent now, call tcp_output() to try to send
after calling tcp_write().

Reply all
Reply to author
Forward
0 new messages