如何使用ZeroMQ从MetaTrader终端发送外汇汇率&使用ZeroMQ将它们记录在nodejs服务器中?

时间:2017-02-12 17:38:38

标签: node.js zeromq metatrader4

我的nodejs / express server.js文件:

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}`);
});

为了将外汇汇率从MetaTrader终端发送到tcp://127.0.0.1:3000,我需要做什么?MetaTrader终端与nodejs应用程序并行运行?

基本上我想使用socket.io向客户端发送它们。

1 个答案:

答案 0 :(得分:1)

在您的专家中,我认为这样的事情会起作用。没试过。

#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);
}

我很想知道你打算如何解码从MT4发送的缓冲区。我无法让node.js读取正确的编码。

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');