Pages: 1 [2] 3   Go Down
Author Topic: W5100/Ethernet cannot use socket as UDP after using it as TCP  (Read 5010 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sometimes I amaze myself!  smiley-cool

Remove the Udp.begin(8888) from setup, and use this checkTime function. How does it do? Works ok here.
Code:
void checkTime()
{
if(!Udp.begin(8888)) {
          Serial.println("UDP fail");
          return;
        }

  sendNTPpacket(Udp, timeServer); // send an NTP packet to a time server
Serial.println("");
ShowSockStatus();
// wait to see if a reply is available
delay(1000); 
if ( Udp.parsePacket() ) { 
// We've received a packet, read the data from it
Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer

//the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord; 

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;     
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears; 
// print Unix time:
Serial.println(epoch); 

else
Serial.println("UDP FAIL!");
Udp.stop();

}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's a much simpler example using the built in DNS library:

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <utility/w5100.h>
#include "Dns.h"

void ShowSockStatus()
{
for (int i = 0; i < MAX_SOCK_NUM; i++) {
Serial.print("Socket#");
Serial.print(i);
uint8_t s = W5100.readSnSR(i);
Serial.print(":0x");
Serial.print(s,16);
Serial.print(" ");
Serial.print(W5100.readSnPORT(i));
Serial.print(" D:");
uint8_t dip[4];
W5100.readSnDIPR(i, dip);
for (int j=0; j<4; j++) {
Serial.print(dip[j],10);
if (j<3) Serial.print(".");
}
Serial.print("(");
Serial.print(W5100.readSnDPORT(i));
Serial.println(")");
}
}

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetServer server(80);
IPAddress dnsserver(192,168,10,1);
IPAddress ip(192,168,10,20);
IPAddress gateway(192,168,10, 2);
IPAddress subnet(255, 255, 255, 0);

long timer;

void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
delay(500);

Serial.println("Start!");
server.begin();
ShowSockStatus();
timer = millis();
}

void loop()
{
//Check if a web client has attached.
EthernetClient client = server.available();
if (client) {
Serial.println("new Client");
ShowSockStatus();
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
if (c == '\n' && currentLineIsBlank) {
client.stop();
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}

if ((millis() - timer) > 5000) {
DNSClient dns;
IPAddress remote_addr;
dns.begin(dnsserver);
if (dns.getHostByName("www.yahoo.com", remote_addr) == 1)
{
for (int i=0; i<4; i++) {
Serial.print(remote_addr[i]);
if (i!=3)
Serial.print('.');
else
Serial.println("");
}
}
else
Serial.println("DNS FAIL!");
timer = millis();
ShowSockStatus();
}
}

And the output

Code:
Start!
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 0 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
98.139.183.24
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1030 D:192.168.10.1(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
98.138.253.109
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1024 D:192.168.10.1(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
98.138.253.109
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1024 D:192.168.10.1(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.10.213(11298)
Socket#1:0x17 80 D:192.168.10.213(11299)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.10.20
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
98.139.183.24
Socket#0:0x0 1035 D:192.168.10.1(53)
Socket#1:0x17 80 D:192.168.10.213(11299)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
98.138.253.109
Socket#0:0x0 1029 D:192.168.10.1(53)
Socket#1:0x17 80 D:192.168.10.213(11299)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
98.139.183.24
Socket#0:0x0 1039 D:192.168.10.1(53)
Socket#1:0x0 80 D:192.168.10.213(11299)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.10.213(11312)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x17 80 D:192.168.10.213(11311)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.10.20
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
98.138.253.109
Socket#0:0x17 80 D:192.168.10.213(11312)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x0 1033 D:192.168.10.1(53)
Socket#3:0x0 0 D:0.0.0.0(0)
98.139.183.24
Socket#0:0x17 80 D:192.168.10.213(11312)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x0 1028 D:192.168.10.1(53)
Socket#3:0x0 0 D:0.0.0.0(0)
98.138.253.109
Socket#0:0x17 80 D:192.168.10.213(11312)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x0 1039 D:192.168.10.1(53)
Socket#3:0x0 0 D:0.0.0.0(0)
DNS FAIL!
Socket#0:0x0 1034 D:192.168.10.1(53)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x0 1039 D:192.168.10.1(53)
Socket#3:0x0 0 D:0.0.0.0(0)
DNS FAIL!
Socket#0:0x0 1033 D:192.168.10.1(53)
Socket#1:0x14 80 D:192.168.10.213(11299)
Socket#2:0x0 1039 D:192.168.10.1(53)
Socket#3:0x0 0 D:0.0.0.0(0)


Notice how it works right up till it tries to reuse socket #0 to do the DNS (which has previously been used as UDP/DNS and then TCP).  Then it fails...
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I use a reliable dns server, I cannot replicate your error with my code. Both NTP and DNS work. Is 192.168.10.1 a good dns server? My NTP and DNS changes sockets (they both use the same socket) and has no problem. ??
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using the code I put in the message?  There shouldn't be any NTP packets going across because there's nothing NTP related in that code. 

It's a reliable DNS server.  If I never browse to the web port on the Arduino then it'll sit there and poll forever with no issues.  In fact it's been up polling for the past 3 hours and has not had a single failure.  As soon as I browse to we web port though, it fails (well, I actually have to browse twice for it to happen).
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Are you using the code I put in the message?
I am testing the code from your reply #16 now. I changed the network settings and dns server to mine, and have it resolving my local domain name instead of yahoo. It has not failed yet, despite the requests to the server and the "No data received" message.

When resolving yahoo, I got errors if I try to resolve the name too often, no matter if I loaded the webpage or not.

edit: This is after I removed my SD card from the shield slot. NTP, dhcp and dns have a problem if there is a card in the slot and not disabled or initialized correctly.

It has been running about an hour with several dozen requests to the server, and not one fail of either service.
« Last Edit: April 27, 2013, 06:41:46 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Tim.  I should have mentioned the SD card thing.  I didn't include any initialization code to turn of the SD card.

I guess I'd love to see your output if you have it available...

I'm beginning to think that your setup is just not exhibiting the same things that mine is.  Maybe there's a batch of 5100s that have bugs?  Maybe it's my version of the Ethernet shield.  (I've got a couple that I bought off eBay).  I don't know.  I've used two different shields with three different boards (2 megas and 1 Uno).  I've got no idea why it seems so repeatable on my setup with very varied scenarios, but we can't seem to get yours to exhibit the same thing.

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Give me a bit to setup the test again. I am testing the ethernet shield's dhcp client function. I think my router has a bug in the dhcp server service. I will replace my public ip with a phoney. I don't need any DoS attacks. I get enough, thanks.

Check back in a bit... smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does seem odd that it would fail for a DNS request that only came once every 5 seconds.  That's pretty far from a DoS.  Anyway, I changed my code to use 4.2.2.1 public DNS.  I posted it on the other thread...
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am concerned about DoS when publishing my public ip, and not because of this code. Here is my serial monitor display for a short run. It will go on for hours like this.
Quote
Start!
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 0 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1024 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1036 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1031 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.1.254(3691)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x0 1026 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x17 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1038 D:xx.xx.58.115(53)
Socket#2:0x17 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1034 D:xx.xx.58.115(53)
Socket#2:0x0 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.1.254(3694)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x14 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x0 1029 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x14 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x17 80 D:192.168.1.254(3698)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1024 D:xx.xx.58.115(53)
Socket#2:0x17 80 D:192.168.1.254(3698)
Socket#3:0x0 0 D:0.0.0.0(0)
a
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1024 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1036 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 1031 D:xx.xx.58.115(53)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.1.254(3691)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x0 1026 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x14 80 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3692)
Socket#2:0x17 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1038 D:xx.xx.58.115(53)
Socket#2:0x17 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1034 D:xx.xx.58.115(53)
Socket#2:0x0 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x17 80 D:192.168.1.254(3694)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x14 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x0 1029 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x14 80 D:192.168.1.254(3693)
Socket#3:0x0 0 D:0.0.0.0(0)
new Client
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x17 80 D:192.168.1.254(3695)
Socket#2:0x17 80 D:192.168.1.254(3698)
Socket#3:0x0 0 D:0.0.0.0(0)
GET / HTTP/1.1
Host: 192.168.2.2
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

client disconnected
xx.xx.58.116
Socket#0:0x14 80 D:xx.xx.58.115(53)
Socket#1:0x0 1024 D:xx.xx.58.115(53)
Socket#2:0x17 80 D:192.168.1.254(3698)
Socket#3:0x0 0 D:0.0.0.0(0)
« Last Edit: April 28, 2013, 11:52:17 am by SurferTim » Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1881
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my 2 cents;-

UDP is a lightweight protocol that by design doesn't handle things like packet sequencing. It does not guarantee that your packets will arrive in order (It does not even guarantee that your packets will arrive at all.) .
Say send command  set voltage=1 v, then set voltage=4 v, You might get 0v or 1v or 4v if default is 0v. TCP is a better choice if you want robust packet delivery and sequencing.
If you're limited to using UDP you would have to develop a method of identifying the out of sequence packets and resequencing them or request to resend, but for Arduino is tough task.

a lot people implement UDP with Arduino, I mean neither OP nor this thread please hold fire.

I guess either they drink too much Italian coffee or I drink too much, might be both.  smiley-razz
« Last Edit: April 28, 2013, 11:58:26 am by sonnyyu » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@sonnyyu: That is a good thought, but NTP, DNS, and DHCP use UDP. You really can't avoid it.

Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1881
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@sonnyyu: That is a good thought, but NTP, DNS, and DHCP use UDP. You really can't avoid it.



I mean neither OP nor this thread please hold fire.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not firing at you.  smiley  I'm just stating a fact. I am not fond of UDP either as a reliable transfer, but we are subjected to it through theses services.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,  that's 100% definitive.  You are not having the same issue as I am, although I have no idea why...

One thing I just found out was that if the TCP request comes from the same machine as the UDP destination goes to (i.e. if you run a WGET from the same router that's hosting your DNS server) the problem never happens (for me).  It's almost like it's a IP->MAC arp issue.  Odd.  I'm going to delve into this a bit more before I bother anyone.  Looking up W5100 and ARP I did come up with this:  http://forums.parallax.com/showthread.php/129515-W5100-Sn_SR-undocumented-misfeature-bug  Not sure if that's related though...  I'll get to the bottom of this at some point...

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 149
Posts: 6117
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you are right. Maybe the delay waiting for the response from the dns server is not long enough. That could cause the dns fail.

edit: Your test is still running on my Arduino. It has not missed a beat since I started it.
Just so you know...
« Last Edit: April 28, 2013, 12:20:36 pm by SurferTim » Logged

Pages: 1 [2] 3   Go Up
Jump to: