0

My nodejs / express server.js file:

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');

const zmq = require('zeromq');
const sock = zmq.socket('pull');

const port = 3000;

sock.connect('tcp://127.0.0.1:3000');
console.log('Worker connected to port 3000');

sock.on('message', function(msg){
    console.log('work: %s', msg.toString());
});

http.listen(port, () => {
    console.log(`listening on ${port}`);
});

What do I need to do in order to send forex rates to tcp://127.0.0.1:3000 from MetaTrader Terminal, which is running locally in parallel with the nodejs application?

Basically I want to emit them using a socket.io to the clients.

user3666197
  • 1
  • 6
  • 50
  • 92
Georgi Antonov
  • 1,581
  • 21
  • 40

1 Answers1

1

In your expert, I think something like this will work. Haven't tried it.

#include <zmq_bind.mqh>

int client,server,context;

int init()
{
   return(0);
}

int deinit()
{
   z_close(client);
   z_close(server);
   z_term(context);
   return(0);
}

int start()
{
   Print("using zeromq version "+z_version_string());

   context = z_init(1);
   client = z_socket(context,ZMQ_REQ); //server: receives first
   server = z_socket(context,ZMQ_REP); //client: sends first 

   if(z_bind(server,"tcp://127.0.0.1:3000")==-1) {
      return(-1);  
   }
   if (z_connect(client,"tcp://127.0.0.1:3000")==-1) {
      return(-1); 
   }

   z_send(client,"Hello world");
   Print("message received is " +z_recv(server));

   return(0);
}

I'm curious to know how you plan to decode the buffer sent from MT4. I can't get node.js to read the correct encoding.

var net = require('net');

var server = net.createServer(function (socket) {
    socket.on('data', function (data) {
        socket.write('Echo server\r\n');
    });
});
server.listen(3000, '127.0.0.1');
user3666197
  • 1
  • 6
  • 50
  • 92
Chris Hemmens
  • 367
  • 2
  • 11
  • You might want to know, that this proposal is very misleading, both in structure, and in MQL4 / ZeroMQ implementation details. I use ZeroMQ / MQL4 since v 2.1.11 with many successful integrations, be it a remote-(non-blocking)-syslog consolidation, low-latency collection of QOUTE-stream data for trade-execution audits or for real-time interactions between trading-engine and external AI/ML-predictors. **Your answer may get improved, if you re-design the concept and avoid misleading / weak points if it strives to answer to question in a fair and professionally responsible manner.** – user3666197 Jul 21 '17 at 14:30