[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] lwip udp server
From: |
Çağlar AKYÜZ |
Subject: |
Re: [lwip-users] lwip udp server |
Date: |
Fri, 09 Feb 2007 15:01:32 +0200 |
User-agent: |
Mozilla Thunderbird 1.5.0.9 (Windows/20061207) |
Andrea Visinoni wrote:
Hi all,
Hi,
i'm trying to develop an udp server over an AT91SAM7X-EK board, and
i've some problems.
First of all, tcp is working correctly, and if i ping my board it
replys, i've already done a tcp server and it works.
Is there an example about udp server or udp usage?
Thanks
Andrea
Here is my working UDP server on SAM7X(on a FREERTOS port). After
bringing up a mac interface you can init connection. In this example,
only connections from a predefined IP address is accepted. This is not
neccessary.
Regards
Caglar AKYUZ
void init()
{
/* create a new UDP connection */
listen_pc = netconn_new( NETCONN_UDP );
/* set up the IP address of the remote host. This is one is
192.168.2.7.
* this is not that much neccessary.
*/
addr.addr = htonl(( 192 << 24 ) | ( 168 << 16 ) | ( 100 << 8 ) | (
7 << 0 ));
/* connect the connection to the remote host */
netconn_connect(listen_pc, &addr, 15000 );
/* Make datagram_recved callback function and bind to the local port
* When there is a packet recved from the network our datagram_recved
* function will be called.
*/
udp_recv( listen_pc->pcb.udp, datagram_recved, NULL );
netconn_bind( listen_pc , NULL , 33333 );
/* create a new netbuf. This buffer is for referencing ethernet data. */
buf = netbuf_new();
/* Reference the request data into net_buf */
netbuf_ref( buf , (int *)some_data_pointer ,
some_data_length_in_bytes );
/* Then send the datagram */
netconn_send( listen_pc , buf );
}
void datagram_recved(void *arg, struct udp_pcb *pcb, struct pbuf *p,
struct ip_addr *addr, u16_t port)
{
/* Supress compiler warnings */
( void ) arg;
( void ) addr;
( void ) port;
/* Do something with the pbuf */
/* Don't forget to free buffer */
pbuf_free(p);
}