Trying to send char data to my node js server


Sketch for Arduino Code

#include <Arduino.h>
#include <WiFiClient.h>

void setup() {
WiFiClient client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
Serial.println("connected to ");
Serial.println(host);

char msg[10] = "123456789";
//client.println(msg);
client.write((const uint8_t *) msg, 10);
client.stop();
}

void loop() {

}



Sketch for Node JS


actually...I don't know how to receive data from Arduino....
If someone can advise me, please tell me.

I don't know to use socket.io...because I'm making product for sale...
if I use socket.io... node server is for only one device.


http = require('http');
fs = require('fs');
var express=require('express');
var app=express();
const request = require('request');
var router = express.Router();

var server = http.createServer( function(request, response) {
console.dir("param is : "+request.param);
console.log(request.method);
response.setHeader("Content-Type", "text/html");
response.writeHead(200);
response.write('Simple HTTP Server');
response.write('');
for (var idx in messages){
response.write('\n

this is page

');
}
response.end('\n');

if (request.method === 'POST') {

} else {
response.statusCode = 404;
response.end();
}

});

server.listen(process.env.PORT || 13339, function () {
var port = server.address().port;
console.log("EEEEEExpressss is working on port " + port);
});


The Arduino code doesn't compile.

In the Arduino code you seem to establish a simple TCP connection (code is not complete so this is a guess) while the server side code expects a HTTP connection (which is based on TCP but it talks another protocol on top of TCP).

You might need to tell us what exactly you're trying to achieve. And post complete code that shows the problem. BTW: you didn't tell us that you have a problem. I'm just guessing that because you're posting here.