-->
Page 1 of 1

Example Client using Net module

PostPosted: Fri Oct 23, 2015 9:02 am
by Erni
This example use the Net module to fetch a text file on my server.
The server is hosted in a cluster (I think that is what is called, when several domains are hosted with the same IP number)
Therefore it is not enough to just use an IPnumber.

Code: Select allESP8266WiFi.init();
var net = require('net');
var hostname="ernstc.dk";

ESP8266WiFi.getHostByName(hostname, function(ipAddress){

  var client=net.connect({host: ESP8266WiFi.getAddressAsString(ipAddress), port:80}, function() {
   print('Connected');
   client.write('GET /esp.txt HTTP/1.1\r\nHost:' +hostname+'\r\nAccept: */*\r\n\r\n');

client.on('data', function(data) {
   print(data);
});

client.on('close', function() {
   print('Connection closed');
});
});
});

Re: Example Client using Net module

PostPosted: Fri Oct 23, 2015 12:04 pm
by jankop
Good work, thanks!