UDP packet tx/rx / programming question
              in 
             Integration and Hardware 
              •  
              1 year ago    
            
 
           
             import hypermedia.net.*;
            
            
             int PORT_RX=3000; //port  <<<< how to obtain this , i'm using a laptop ????
            
            
             String HOST_IP="195.100.101.60"; //
            
            
             UDP udp;
            
            
             String receivedFromUDP = " ";
            
            
             void setup() {
            
            
               size(400,400);
            
            
               udp= new UDP(this,PORT_RX,HOST_IP);
            
            
               udp.log(true);
            
            
               udp.listen(true);
            
            
               super.start(); 
            
            
               println("start called");
            
            
             }
            
            
             void draw() {
            
            
               background(0);
            
            
               println("entered draw");
            
            
               text(receivedFromUDP, 50, 50);
            
            
             }
            
            
             void receive(byte[] data, String HOST_IP, int PORT_RX) 
            
            
             {
            
            
               println("entered receive ");  // <<<<<   never gets printed, means it never enters this function/when is this function called //and who calls it
            
            
             receivedFromUDP ="";
            
            
               for (int i = 0; i < data.length; i++) {
            
            
                 println("entered loop");
            
            
                receivedFromUDP += str(data[i]) + " ";
            
            
               }
            
            
               println(data);
            
            
             }
            
            
             the corresponding arduino web server program tx the udp packet is..
            
            
              #include <SPI.h>        
             
             
              #include <Ethernet.h>
             
             
              #include <EthernetUdp.h>
             
             
              // Enter a MAC address and IP address for your controller below.
             
             
              // The IP address will be dependent on your local network:
             
             
              byte mac[] = {  
             
             
                0x90, 0xA2, 0xDA, 0x0D, 0x0C, 0xE9 };
             
             
              IPAddress ip(195, 100, 101, 65);
             
             
              unsigned int localPort = 8888;      // local port to listen on
             
             
              // 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);
             
             
              }
             
             
              void loop() {
             
             
                Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
             
             
                  Udp.write("hello");
             
             
                  Udp.endPacket();
             
             
              }
             
             
              
              1  
            
 
            
 
 
          