UDP Send Receive String Garbage data problem

I am trying to run the standard UDP send receive string example sketch on my Uno Rev3+Official Ethernet Shield only to get the following data on the serial console
0.0, port 1Received packet of size 1176

From 192.43.244.18, poþReceived packet of size 1208

From 211.4.225.254, port 44488

Contents:

Received packet of size 1176

From 192.43.244.18, poþReceived packet of size 1208

From 211.4.225.254, port 44488

Contents:

Received packet of size 1176

From 192.43.244.18, poþReceived packet of size 1272

From 32.114.101.113, port 30053

Contents:

. Thatâ??s all we L

Received packet of size 1240

From 107.110.111.119, port 11836

Contents:

ns>

Received packet of size 1208

From 211.4.225.254, port 44488

Contents:

Received packet of size 1176

From 192.43.244.18, port 123

Contents:

Received packet of size 1144

From 0.0.0.0, port 0

Contents:

ÓâE 7 AÓâE 8êNÀ+ô

Received packet of size 1112

From 36.1.6.227, port 0

Contents:

Received packet of size 1080

From 211.4.226.80, port 11070

Contents:

ÓâP+>·?À+ô

Received packet of size 1048

From 0.0.0.0, port 16707

Contents:

Óâ@­ì?

Received packet of size 1272

============================================================
the stream keeps on printing more and more of such data
i have been trying to figure out the problem for hours but have reached no where.
Please help me out

You might want to try the "605 Bug" fix. It does affect udp.
http://code.google.com/p/arduino/issues/detail?id=605

It affects IDE versions from v0022 to v1.0

Just a thought...

does not work :frowning:
the response is still the same...

Then it is time for you to post your code. Maybe something wrong there.

edit: Did you notice all these packet sizes are larger than 1023? That is normally a sign of the "605 Bug".

Received packet of size 1176
// starts at about 1300, decreasing every check...
Received packet of size 1240
Received packet of size 1208
Received packet of size 1176
Received packet of size 1144
Received packet of size 1112
Received packet of size 1080
Received packet of size 1048
// ... and works down to 1024, then starts over
Received packet of size 1272

its the sample code that came along....

/*
UDPSendReceive.pde:
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender

A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.

created 21 Aug 2010
by Michael Margolis

This code is in the public domain.
*/

#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888; // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);

Serial.begin(9600);
}

void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote*, DEC);*

  • if (i < 3)*

  • {*
    _ Serial.print(".");_

  • }*

  • }*
    _ Serial.print(", port ");_
    _ Serial.println(Udp.remotePort());_

  • // read the packet into packetBufffer*

  • Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);*
    _ Serial.println("Contents:");_
    _ Serial.println(packetBuffer);_

  • // send a reply, to the IP address and port that sent us the packet we received*

  • Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());*

  • Udp.write(ReplyBuffer);*

  • Udp.endPacket();*

  • }*

  • delay(10);*
    }
    /*

  • Processing sketch to run with this example*

  • =====================================================*

  • // Processing UDP example to send and receive string data from Arduino *

  • // press any key to send the "Hello Arduino" message*

_ import hypermedia.net.*;_

  • UDP udp; // define the UDP object*

  • void setup() {*

  • udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000*

  • //udp.log( true ); // <-- printout the connection activity*

  • udp.listen( true ); // and wait for incoming message *

  • }*

  • void draw()*

  • {*

  • }*

  • void keyPressed() {*

  • String ip = "192.168.1.177"; // the remote IP address*

  • int port = 8888; // the destination port*

  • udp.send("Hello World", ip, port ); // the message to send*

  • }*

  • void receive( byte[] data ) { // <-- default handler*

  • //void receive( byte[] data, String ip, int port ) { // <-- extended handler*

  • for(int i=0; i < data.length; i++) *
    _ print(char(data*)); [/color]_
    _
    println(); _
    _
    }_
    _ /_
    _
    [/quote]
    _

How many udp packets are you sending to get that many results?
What are you sending in each packet? More than 1000 characters per packet?

Thats the issue......this is the result when i have sent none!
it does not accept the datagrams i send to it via a c socket program.

Are you certain that you patched the 605 bug? That is almost a textbook example of that bug.

i replaced the lines of code as instructed...is there anything else required?

Just recompile the sketch code and upload it again.

I use two versions of the IDE (0022 and 1.0). Both required that patch. I was unpleasantly surprised to find that bug in the new version. It was reported back in August 2011.

Insure you are replacing the code in the correct file.

thank you soo much!
it is working fine now :slight_smile:

You are welcome so much! :slight_smile:

If you want to do me a favor now...go to this link and post a comment that this fix helped you.
http://code.google.com/p/arduino/issues/detail?id=605

Maybe if they get bothered enough, they will fix it.