[En-Nut-Discussion] UDP Server Problem

Ernst Stippl ernst at stippl.org
Fri Feb 16 18:55:18 CET 2007


Hi!

This is how I did it some time ago: This was an verfy simplistic attempt to
enquire for a specific snmp information.
maybe it helps

regards
ernst

--------------------------------------------------------------begin

{
UDPSOCKET *udp_sock;
u_short    remoteport;
u_long    *pRemoteaddr;
u_short   *pRemoteport;
u_short    writelen;
u_short    readlen;
u_long     timeout;
u_short    localport;
u_short    r;
u_char    *resultstring; 

remoteport = 161;

writelen = len;
timeout = 10000;
pRemoteaddr = &remoteaddr;
pRemoteport = &remoteport;
readlen = 0; 
localport = 0;

udp_sock = NutUdpCreateSocket(localport);    // create socket
if (udp_sock != 0) 
   IF_LOG_SNMP printf("SNMP: UDP Socket port %d\n",
udp_sock->so_local_port);   

   
//  SNMP request Send an UDP datagram.     
     
r = NutUdpSendTo ( udp_sock, remoteaddr, remoteport, SNMP_buff, writelen);
	  
if (r!=0) 
IF_LOG_SNMP printf ("SNMP: UdpSendTo: %s %d\n", inet_ntoa (remoteaddr), r);

  
remoteport = 0;
remoteaddr = inet_addr ("0.0.0.0");

r = NutUdpReceiveFrom ( udp_sock, 
                        pRemoteaddr, 
						      pRemoteport, 
					      	SNMP_buff, 
					      	SNMP_buff_size, 
					      	timeout);
IF_LOG_SNMP printf ("SNMP: UdpReceiveFrom: %d %d-%s:%u\n", r, readlen,
inet_ntoa(remoteaddr), remoteport);

if (r == 0) {                            // timeout
   r = NutUdpDestroySocket(udp_sock); 
   return 0;
   }
   
else if (r == -1) {                      // error
   IF_LOG_SNMP printf ("SNMP: UdpReceiveFrom Fehler %s %d\n",
inet_ntoa(remoteaddr), r);
   r = NutUdpDestroySocket(udp_sock); 
   return 0;
   }   
   
resultstring = decode_snmp_response (r);
IF_LOG_SNMP printf ("SNMP: result string found at %d\n", r);

r = NutUdpDestroySocket(udp_sock);       // destroy Socket
IF_LOG_SNMP printf ("SNMP: UdpDestroySocket: %d\n", r); 
}
--------------------------------------------------------------end
-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von MUHAMMAD AZEEM
AZAM
Gesendet: Freitag, 16. Februar 2007 11:50
An: Ethernut User Chat (English)
Betreff: Re: [En-Nut-Discussion] UDP Server Problem

Hi
   
  for(;;)
  {
 
 if ((sock = NutUdpCreateSocket(23)) != 0) 
  
  {
     u_long ip_addr= inet_addr("192.168.5.2");
   u_short port = 2050;
   
   
   NutUdpReceiveFrom (sock,&ip_addr,&port,buff,sizeof(buff),1000);
     NutUdpSendTo(sock,inet_addr("192.168.5.2"),port,"azam",4);
  }
 
 NutUdpDestroySocket(sock);
 
NutSleep(125);
  }

  The above thing is not working.
  its the simplest
   
  THanks
  
Jose Vicente Sanchez Ortega <jvsanchezo at gmail.com> wrote:
  Hi:

You must implicitly define the address and port since both are input
parameters to NutUdpSendTo and NutUdpReceiveFrom (nobody will fill for you
this fields neither in Receive nor in Send.

Regards,



-----Mensaje original-----
De: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] En nombre de MUHAMMAD AZEEM
AZAM Enviado el: jueves, 15 de febrero de 2007 18:20
Para: Ethernut User Chat (English)
Asunto: Re: [En-Nut-Discussion] UDP Server Problem

hi

this means when i will call the
---------------------
NutUdpReceiveFrom() function
its parametrs
addr will contain address of my client.
and port will contain port of my client.
--------------------------
then i should use NutUdpSendTo() to send my data to the Port and addr that i
have received in NutUdpReceiveFrom() function.
I don't need to implicitly define the address and port.
like that
unsigned port = 400;
unsigned ip = inet_addr("192.168.0.0");

-------------------------------------------
bye
Jose Vicente Sanchez Ortega wrote:
Hi, MUHAMMAD:

1) UDP is not a stream-oriented protocol (actually is a datagram-oriented
protocol) thus you cannot link an UDP socket with a stream. You must call
the respective functions (i.e. NutUdpReceiveFrom).

2) Yes, you are right.

Bes regards,


Jose Vicente.


-----Mensaje original-----
De: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] En nombre de MUHAMMAD AZEEM
AZAM Enviado el: jueves, 15 de febrero de 2007 16:38
Para: en-nut-discussion at egnite.de
Asunto: [En-Nut-Discussion] UDP Server Problem

hi
I have to build a UDP Server
But

1) i can't assign stream to udp.
so will the string functions will work or not.
like
strcpy
strcmp
2) int NutUdpReceiveFrom ( UDPSOCKET * sock, u_long
* addr, u_short * port, void * data, u_short size, u_long timeout ) 

addr will contain the Ip address of my client(host) and port will contain
port of my client? 



---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



---------------------------------
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.1/690 - Release Date: 16.02.2007
14:25




More information about the En-Nut-Discussion mailing list