I wanted to code something that will stream UDP data. Seems the IP has to be valid for that to work.
Isn't UDP suppose to be connectionless? It seems the w5100 takes longer to send a packet to a non existing host, is there a way to tweak this?
Seems the IP has to be valid for that to work.
Well, now, there's a surprise. You must specify a valid destination. Otherwise, how is the packet supposed to know where to go?
Isn't UDP suppose to be connectionless?
It is, in the sense that a new connection is made for each packet. The existence of that connection/path can not be relied on to ever exist again.
It seems the w5100 takes longer to send a packet to a non existing host
Basically, the packet spends a bunch of time bouncing around before it decides that it can't get there from here. That it takes a while to discover that should come as no surprise.
is there a way to tweak this?
You mean aside from the obvious?
PaulS:
Seems the IP has to be valid for that to work.
Well, now, there's a surprise. You must specify a valid destination. Otherwise, how is the packet supposed to know where to go?
Well as far as I read UDP is simply just packaging up your data into a IP packet with a Destination. Although I think i see what you mean, W5100 is trying to do an arp lookup (completely forgot about that), I think that's my problem.
UDP doesn't actually make a connection, rather a send and forgot delivery. Hence you can broadcast a UDP packet, err 255.255.255.255 and multicast IP's.
[quote author=Drake Dragon link=topic=59019.msg424694#msg424694 date=1303301323]
...
Well as far as I read UDP is simply just packaging up your data into a IP packet with a Destination.[/quote]I agree.
[quote author=Drake Dragon]
Although I think i see what you mean, W5100 is trying to do an arp lookup (completely forgot about that)[/quote]Not necessarily. If the remote IP is on a different network segment than the local IP, there may be an ARP or two.
[quote author=Drake Dragon]UDP doesn't actually make a connection, rather a send and forgot delivery. [/quote]I agree.
Well, what happens here depends on your network connections. If the only thing on your network is your Arduino stuff, the broadcast address isn't terribly important as long as it's on the same network segment as the local IP address. If the Arduino network is connected to a router or switch or something that does packet forwarding to a broader network, then you could be spewing things to the world, depending on how things are set up. (I know, I know...Routers are never supposed to forward anything with address 255.255.255.255, but I would rather just limit the broadcast to a particular segment.)
Here's an example:
/*
Broadcast UDP messages
davekw7x
This code is in the public domain.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <Udp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// Source address. My LAN is 10.10.5.0/24
byte localIp[] = {10, 10, 5, 177};
// Source port
unsigned int localPort = 12346;
// Ethernet net mask will be 255.255.255.0, so this sends
// to all listeners on this segment.
// If the broadcast address does not match the net mask,
// all bets are off
//
byte remoteIp[4] = {10, 10, 5, 255};
// Destination port: Others will be listening here
unsigned int remotePort = 13333;
void setup()
{
// Set up local mac and IP stuff inside the W5100. Note
// that this uses default net mask of 255.255.255.0
Ethernet.begin(mac, localIp);
// Open a socket on the 5100 to set up for sending on this port
Udp.begin(localPort);
}
void loop()
{
delay(1000);
Udp.sendPacket("Hi", remoteIp, remotePort);
}
Use wireshark or other sniffer. The only traffic generated by this sketch is a UDP packet each second. See Footnote.
For this sketch, I opened the socket and kept it open since that's what I think you would be doing for streaming.
Regards,
Dave
Footnote:
If the remote IP is on a different segment from the local IP, there may be some ARPing stuff going on. But I said that already.