lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] TCP server netconn API


From: Saket Chawla
Subject: [lwip-users] TCP server netconn API
Date: Sun, 5 Feb 2012 18:38:45 +0530

I am trying to build a simple TCP echoserver and client for same using netconn API.
I am sure some might already have tried but i couldn't find any source on internet


My system is running ubuntu 10.10

Directory structure to refer for compile instruction
   /contrib
   /lwip
   /server.c
   /lwipopts.h


File content

    lwipopts.h  [i think there might me more required here that i don't know of]

#define LWIP_SOCKET    0


     server.c  [took the basic code from Design and Implementation of the lwIPTCP/IP Stack]

#include <stdio.h>
#include <lwip/api.h>

int main()
{
struct netconn *conn, *newconn;
err_t err;

/* create a connection structure */
conn = netconn_new(NETCONN_TCP);

/* bind the connection to port 2000 on any local IP address */
netconn_bind(conn, NULL, 7);

printf("Now listening\n");
/* tell the connection to listen for incoming connection requests */
netconn_listen(conn);

/* Grab new connection. */
err = netconn_accept(conn, &newconn);
printf("accepted new connection %p\n", newconn);

/* Process the new connection. */
if (err == ERR_OK) 
{
struct netbuf *buf;
void *data;
u16_t len;
   
while ((err = netconn_recv(newconn, &buf)) == ERR_OK) 
{
printf("Received data\n");
do{
netbuf_data(buf, &data, &len);
err = netconn_write(newconn, data, len, NETCONN_COPY);
if (err != ERR_OK)
printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err));
}while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}

/* Close connection and discard connection identifier. */
netconn_close(newconn);
netconn_delete(newconn);
}

}


compile instruction

gcc -I. -I lwip/src/include/ -I contrib/ports/unix/include/ -I lwip/src/include/ipv4/ lwip/src/api/*.c lwip/src/core/*.c lwip/src/core/ipv4/*.c contrib/ports/unix/sys_arch.c lwip/src/netif/etharp.c -lpthread server.c 


Problem
All files are included and no errors / warnings occur for compile
But in netconn_bind I receive an error

Assertion "netconn_bind: invalid conn" failed at line 172 in lwip/src/api/api_lib.c
Aborted

Please let me know if i am missing something obvious
Also i did try to understand the server implementation from simhost but it is too complicated for a basic echoserver application
So any reference manual or if someone has already build such application  for a start then a link to it is deeply appreciated.

--

Thanks
Regards
Saket Chawla

reply via email to

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