UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Contributor
Contributor
7,035 Views
Registered: ‎04-16-2008

An echo server designed with lwip. Help needed

Hi guys:
    I have designed an echo server with lwip3.0 in EDK9.2. The lwip works in socket mode. I use the sp3e500e (the starter kit board).
    Now I want to make my PC work as a client to verify the design. My problem is that how could I program the client on PC? If someone could give me an validated design, I will sincerely appreciate it.
 
Here is my design of server:
 

// Located in: microblaze_0/include/xparameters.h
#include "xparameters.h"
#include "xmk.h"
#include "stdio.h"
#include "lwip/sockets.h"
#include "lwipopts.h"
#include "lwip/inet.h"
#include "netif/xadapter.h"
#include "lwip/sys.h"

void* processConnection(void* arg){
 char revbuf[RECV_BUFFER_SIZE];
 int bytereceived;
 int sd=*((int*) arg);
 char sendbuf[1024]="send data from FPGA";
 lwip_write(sd,sendbuf,1024);
 bytereceived=lwip_read(sd,revbuf,RECV_BUFFER_SIZE);
 xil_printf("received data length is %d\r\n",bytereceived);
 xil_printf("received data is %s\r\n",revbuf);
}
 
void* serverAppThread(void){
 struct netif* pnetif;
 struct netif servernetif;
 struct ip_addr ipaddr, netmask, gw;
 struct sockaddr_in address, remote;
 int sock;
 int new_sd;
 int size;
      unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };   
    IP4_ADDR(&ipaddr, 192, 168, 1, 224);
    IP4_ADDR(&netmask, 255, 255, 255, 0);
    IP4_ADDR(&gw, 192, 168, 1, 1);    
     pnetif=&servernetif;    
    if (!xemac_add(pnetif, &ipaddr, &netmask, &gw, mac_ethernet_address, ETHERNET_MAC_ADDRESS))
     {
        xil_printf("Error adding N/W interface\n\r");
        return;
        } 
    netif_set_default(pnetif);
     netif_set_up(pnetif);
      sys_thread_new((void(*)(void*))xemacif_input_thread, pnetif, 1);
      
    sock = lwip_socket(AF_INET, SOCK_STREAM, 0);
    address.sin_family      = AF_INET;
    address.sin_port        = htons(8080);
    address.sin_addr.s_addr = INADDR_ANY;
    lwip_bind(sock, (struct sockaddr*)&address, sizeof(address));
    xil_printf("Server initialization complete.\r\n");       
 
    lwip_listen(sock,4);
    size=sizeof(remote);
    new_sd = lwip_accept(sock, (struct sockaddr *)&remote, &size);
    xil_printf("accepted from socket %d\r\n",new_sd);
    sys_thread_new((void *)&processConnection, &new_sd, 1);
}
void* serverThread(void){
     lwip_init();
    sleep(300);
    sys_thread_new((void *)&serverAppThread, 0, 1);
}
int main (void) {
   xillkernel_main();    //The serverThread() gets executed;
   return 0;
}
 
0 Kudos
1 Reply
Visitor tsemer
Visitor
3,512 Views
Registered: ‎02-04-2008

Re: An echo server designed with lwip. Help needed

Hi,

 

you may use hyperTerminal if you work under windows or any other terminal application on linux  and ping on your server.

 

good luck

0 Kudos