How to record what is received on an Apache port directly in mysql?

Asked

Viewed 158 times

1

Hello. I have a server Apache (XAMPP) and need to receive messages from a device that sends messages to a specific IP and port. I would like to configure the Apache to listen to a door (443, for example) and record everything it receives/listens to mySQL, inserting into a specific table of the database. We will call the database DB and the table to be saved is the mensagens, that owns the fields codigo (INT, auto increment), mensagem (VARCHAR(200)).

Is that possible? Any suggestions?

  • 1

    Native Apache don’t do that. It seems to be the case of specific application for the purpose, via sockets (unless you modify the device to make HTTP requests).

1 answer

1

Apache implements the HTTP protocol. If your application speaks HTTP, you can talk to APACHE. On the server side, Apache can forward the message to a CGI (in Python, Perl, etc.) or to a language (server side), such as PHP or ASP. In CGI, PHP, ASP, etc, you take the message and write it in Mysql.

If you really just want to send a message to an IP and a port, without having to use the HTTP protocol, the easiest is to write a server in Python, Perl or Node.js. I would recommend writing a server in Node.js, because it gets very, very good performances, since it is asynchronous.

For example, creating a server in Node.js is as simple as creating a server in Node.js:

require('net').createServer(function (socket) {
    socket.on('data', function (data) {
        console.log(data.toString());
    });
}).listen(7777);

Running the program with node servidor.js, This server does not write the message in Mysql (to have only 5 lines). Write only in the console what you receive.

A customer can connect and send the message. Example of a client (also in Javascript):

var s = require('net').Socket();
s.connect(7777, 'localhost');
s.write('Oi!\n');
s.on('data', function(d){
    console.log(d.toString());
});
s.end();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.