2013-04-01 51 views
0

方案:我能發送字符串類型的使用下面的代碼從C#中的Node.js應用程序通過ZeroMQ(ØMQ)數據:
C#推代碼:無法從ZeroMQ接收確認(ØMQ)

using (var context = new Context(1)) 
       { 
        using (Socket client = context.Socket(SocketType.PUSH)) 
        { 
         client.Connect("tcp://127.0.0.1:12345"); 
         int i = 0; 
         while (true) 
         { 
          string request = i.ToString() + "_Hello_ "; 
          i++; 
          Console.WriteLine("Sending request..." + i.ToString()); 
          client.Send(request, Encoding.Unicode); 

           // <== Here is the issues  
          string reply = client.Recv(Encoding.Unicode).ToString(); 
           // <== Here is the issues 

          Console.WriteLine("Received reply :", reply); 
         } 
        } 
       } 

Node.js的拉碼:

pull_socket.bindSync('tcp://127.0.0.1:12345') 

pull_socket.on('message', function (data) { 
    i++; 
    console.log(i.toString() + 'received data:\n'); 
    console.log(data.toString()); 
    pull_socket.send('rcvd'); // <== Here is the issues 
}); 

問題:在C#reply對象將包含字符串"Not supported",但發送的數據將在Node.js正確接收。

問題:可以告訴我我在哪裏做錯了嗎?請說明問題。

高級感謝

回答

0

它得到了通過使用不同的插槽類型REQ解決/ REP,而不是推/拉
以下是代碼:
C#代碼推:

using (var context = new Context(1)) 
       { 
        using (Socket client = context.Socket(SocketType.REQ)) 
        { 
         client.Connect("tcp://127.0.0.1:12345"); 
         int i = 0; 
         while (true) 
         { 
          string request = i.ToString() + "_Hello_ "; 
          i++; 
          Console.WriteLine("Sending request..." + i.ToString()); 
          client.Send(request, Encoding.Unicode); 

          string reply = client.Recv(Encoding.Unicode).ToString(); 

          Console.WriteLine("Received reply :" + reply); 
         } 
        } 
       } 

Node.js的拉代碼:

var rep_socket = zmq.socket('rep') 
rep_socket.bindSync('tcp://127.0.0.1:12345') 

rep_socket.on('message', function (data) { 
    i++; 
    console.log(i.toString() + 'received data:\n'); 
    console.log(data.toString()); 
    pull_socket.send('hello WORLD'); // <== Here is the issues 
}); 

C#控制檯上的輸出:

Sending request...0 
Received reply: hello WORLD