[Top][All Lists]

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

Re: [lwip-users] LWIP Simple echo server:

From: address@hidden
Subject: Re: [lwip-users] LWIP Simple echo server:
Date: Wed, 03 Dec 2008 21:30:18 +0100
User-agent: Thunderbird (Macintosh/20081105)

You did not say which platform you are running on nor which version of lwIP you are using. Please download the contrib module and take a look at the example applications in the windows or unix port to get an idea of how to start with lwIP.


sandy tewari wrote:
I am new to LWIP and im trying to build a echo server application using Sockets API, i dont know what i am doing wrong, im guessing i am not initialising few modules or something. pls help.

int main(){
  printf("Main ");
  return 0;

#include <unistd.h>
#include <getopt.h>

#include "lwip/init.h"

#include "lwip/debug.h"

#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"

#include "lwip/stats.h"

#include "lwip/ip.h"
#include "lwip/ip_frag.h"
#include "lwip/udp.h"
#include "lwip/snmp_msg.h"
#include "lwip/tcp.h"
#include "lwip/tcpip.h"
#include "lwip/sockets.h"
#include "mintapif.h"
#include "netif/etharp.h"

#include "timer.h"
//#include "sys/socket.h"
//#include <arpa/inet.h>

#include <signal.h>

#include "server.h"
#include "private_mib.h"
#define MY_PORT         9999
#define MAXBUF          1024
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;

void socketserver_thread();

void socketserver_init(void)
  debug_flags = LWIP_DBG_ON;
sys_thread_new("socketserver_thread", socketserver_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); }

// Sequential APIs have to be a part of separate thread
void socketserver_thread(){
  int sockfd;
  struct sockaddr_in self;
  char *buffer;

  printf("//Creating stream socket");
  if((sockfd = lwip_socket(PF_INET, SOCK_STREAM,0)) < 0)
      printf("Socket error");
      return -1;

  // Initialise address/port structure
  bzero(&self, sizeof(self));
  self.sin_family = AF_INET;
  self.sin_port = htons(MY_PORT);
  self.sin_addr.s_addr = INADDR_ANY;

  // Bind the socket to port
  if ( lwip_bind(sockfd, (struct sockaddr*)&self, sizeof(self)) != 0 )
     printf("socket--bind error");
     return -1;

  // Make it a listening socket
  if( lwip_listen(sockfd, 20) != 0)
     printf("socket--listen error");
     return -1;
  /*---Forever... ---*/
  while (1)
{ printf("WAiting for connection");
      int clientfd;
      struct sockaddr_in client_addr;
      int addrlen=sizeof(client_addr);
      /*---accept a connection (creating a data pipe)---*/
clientfd = lwip_accept(sockfd, (struct sockaddr*)&client_addr, &addrlen); printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));

      /*---Echo back anything sent---*/
      lwip_send(clientfd, buffer, recv(clientfd, buffer, MAXBUF, 0), 0);

      /*---Close data connection---*/

  /*---Clean up (should never get here!)---*/
  return 0;


lwip-users mailing list

reply via email to

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