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: 
Observer yunusy
Observer
6,137 Views
Registered: ‎03-13-2014

LwIP - 'Echo server' to 'Server and Client'

Hi. I've been trying to modify LwIP echo server example into a Server&Client application.

I can succesfully run default echo server example.

And for the next step:

I have an ethernet hardware that connects Gem0 and Gem1 internally.

In order to achive that, these are the codes that I modified.

main.c

 

struct ip_addr ipaddr, netmask, gw;
	struct ip_addr ipaddr2, netmask2, gw2;

	/* the mac address of the board. this should be unique per board */
	unsigned char mac_ethernet_address[] =
	{ 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };
	unsigned char mac_ethernet_address2[] =
	{ 0x00, 0x0a, 0x35, 0x00, 0x01, 0x04 };

	echo_netif = &server_netif;
	echo_netif2 = &server_netif2;

#if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1
	ProgramSi5324();
	ProgramSfpPhy();
#endif

	init_platform();

	/* initliaze IP addresses to be used */
	IP4_ADDR(&ipaddr,  192, 168,   1, 10);
	IP4_ADDR(&netmask, 255, 255, 255,  0);
	IP4_ADDR(&gw,      192, 168,   1,  1);

	/* initliaze IP addresses to be used */
	IP4_ADDR(&ipaddr2,  192, 168,   1, 11);
	IP4_ADDR(&netmask2, 255, 255, 255,  0);
	IP4_ADDR(&gw2,      192, 168,   1,  1);
....
....
....
/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(echo_netif, &ipaddr, &netmask,
						&gw, mac_ethernet_address,
						PLATFORM_EMAC_BASEADDR)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(echo_netif);

	/* Add network interface to the netif_list, and set it as default */
	if (!xemac_add(echo_netif2, &ipaddr2, &netmask2,
						&gw2, mac_ethernet_address2,
						PLATFORM_EMAC_BASEADDR2)) {
		xil_printf("Error adding N/W interface\n\r");
		return -1;
	}
	netif_set_default(echo_netif2);

...
...
...
/* specify that the network if is up */
	netif_set_up(echo_netif);
	/* specify that the network if is up */
	netif_set_up(echo_netif2);

	/* start the application (web server, rxtest, txtest, etc..) */
	start_application();/* receive and process packets */
while (1) {
xemacif_input(echo_netif);
transfer_data();
}

 

 

This is my main function. I've created two network interfaces instead of one.

For the echo part of the application. I keep the default parts as server side (Ip:192.168.1.10 , port 7 etc)

And for the client side(this will be connect to the server)

 

int start_application()
{
	struct tcp_pcb *pcb, *pcb2;
	err_t err;
	unsigned port = 7;
	unsigned port2 = 8;
	struct ip_addr ipaddr;
	int retval = 9999;
	IP4_ADDR(&ipaddr,  192, 168,   1, 10);

	/* create new TCP PCB structure */
	pcb  = tcp_new();
	pcb2 = tcp_new();
	if (!pcb) {
		xil_printf("Error creating PCB. Out of Memory\n\r");
		return -1;
	}

	/* bind to specified @port */
	err = tcp_bind(pcb, IP_ADDR_ANY, port);
	if (err != ERR_OK) {
		xil_printf("Unable to bind to port %d: err = %d\n\r", port, err);
		return -2;
	}

	/* bind to specified @port */
	err = tcp_bind(pcb2, IP_ADDR_ANY, port2);
	if (err != ERR_OK) {
		xil_printf("Unable to bind to port %d: err = %d\n\r", port, err);
		return -2;
	}

	/* we do not need any arguments to callback functions */
	tcp_arg(pcb, NULL);
	tcp_arg(pcb2, NULL);

	/* listen for connections */
	pcb = tcp_listen(pcb);
	if (!pcb) {
		xil_printf("Out of memory while tcp_listen\n\r");
		return -3;
	}

	/* specify callback to use for incoming connections */
	tcp_accept(pcb, accept_callback);

	xil_printf("TCP echo server started @ port %d\n\r", port);

	/* set callback values & functions */
	tcp_arg(pcb2, NULL);
	tcp_sent(pcb2, sent_callback);
	tcp_recv(pcb2, recv_callback);
	retval = tcp_connect(pcb2, (ip_addr_t *)(&ipaddr), 7, connection_establisted);
	return 0;
}

 and my callback function on tcp_connect is 

err_t connection_establisted(void *arg, struct tcp_pcb *newpcb, err_t err)
{
    xil_printf("\nConnection callback is called \n");

   return err;


}

 

Problem here is, tcp_connect returns 0 (ERR_OK) but connection_establised() is never called

.

Am I missing something in start_application() function(invalid sequence for tcp_xxx functions,etc) or in the main function(mac addresses, interfaces) ?

0 Kudos
4 Replies
Scholar stephenm
Scholar
6,127 Views
Registered: ‎05-06-2012

Re: LwIP - 'Echo server' to 'Server and Client'

The system is interrupt based. So, make sure that you are not inadvertately disabling interrupts from hemp when setting up gem1.
Adventurer
Adventurer
5,171 Views
Registered: ‎10-17-2014

Re: LwIP - 'Echo server' to 'Server and Client'

Have you solve the problem ??

0 Kudos
Adventurer
Adventurer
5,133 Views
Registered: ‎10-17-2014

Re: LwIP - 'Echo server' to 'Server and Client'

Hi,I have encountered the same question , but I can't understand what you have said , please help me with saying in details.Many thanks!
0 Kudos
Observer zhoukq
Observer
3,666 Views
Registered: ‎07-05-2015

Re: LwIP - 'Echo server' to 'Server and Client'

hello , my friend !

Have you solved the problem?

Can you help me?
0 Kudos