• You can do both UDP and TCP at the same time.

    Wifi.at.cmd("AT+CWMODE_CUR=3\r\n", 1000, function(d){console.log(d+"xx1");});

    You call SetUDP and then setup a network with protocol 17 for UDP.
    Then you call SetTCP and setup either HTTP or a TCP network.

         wifi.SetUDP();
         var client = require("net").connect({host: BroadIP, port: UDPport,protocolVersion: 17}, function() {
    

    Use the UDP to obtain the IP address of the server and then

              wifi.SetTCP();
               getReply(console.log);
    ...
    function getReply(callback) {
      var options = {
        host: ServerIP,
        port: '8080',
        path:"/",
        method:'GET',
        headers: {
        }
      };
      console.log("getReply");
      require("http").request(options, function(res)  {
        var d = "";
        res.on('data', function(data) { d+= data; });
        res.on('close', function(data) {
          var j = JSON.parse(d);
          console.log("d= ",d);//console.log("j= ",j);
          if (callback) callback((j&&j.result)?j.result:undefine­d);
        });
      }).end();
    }//end getReply
    

    On the server side

        wifi.SetUDP();
      var client = require("net").connect({host:BroadIP,por­t:UDPport ,protocolVersion: 17}, function() {
        console.log('client connected');
        client.write(JSON.stringify(UDP1));
        client.on('data', function(data){
         ddata+=data;
         if(ddata.charAt(ddata.length-1)==='}'){
          UDP2=JSON.parse(ddata);
          console.log(">"+ddata);
          if(UDP1.ServerName===UDP2.ServerName){
           UDP2.ServerIP=UDP1.ServerIP;
           client.write(JSON.stringify(UDP2));
           ddata="";
          }//endif
         }//endif
        });//end client on data
        client.on('close',function(){console.log­("client Close");});
        client.on('end', function() {
         console.log('client disconnected');
        });//end client on end
        //client.end();
       });//end UDP client connect
    });//end wifi.getIP
    //HTTP or Network Server goes here
       wifi.SetTCP();
    serveHTML();
    //////////////////
    .....
    function serveHTML(){
    var http=require("http").createServer(onPage­Request).listen(8080);
    }//end serveFile
    
    
    function onPageRequest(req, res) { 
    //console.log("Req= ",req);
    //console.log("Header",req.headers);
    if (req.method=="POST") {
      console.log("Post");
      doPost(req,res);
    }else{
      doGet(req,res);
    }//endif
    }//end on PageRequest
    
    
About