【发布时间】:2016-08-25 03:17:42
【问题描述】:
我正在尝试使用套接字将我的 Ada 应用程序与 node.js 服务器连接起来。 我已经设法将数据从 Ada 发送到 node.js,但在接收数据方面仍然存在问题。
这是我的 Ada 任务:
task body Send_Task is
use Ada.Numerics.Float_Random;
Next : Ada.Real_Time.Time;
Period : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(5000);
Interval : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds(30);
Gen : Generator;
Address : Sock_Addr_Type;
Socket : Socket_Type;
Channel : Stream_Access;
begin
Reset(Gen);
Next := Ada.Real_Time.Clock + Interval;
Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
Address.Port := 9000;
Create_Socket (Socket);
Set_Socket_Option (Socket, Socket_Level, (Reuse_Address, True));
Connect_Socket (Socket, Address);
loop
delay until Next;
Channel := Stream (Socket);
String'Output(Channel, Message'Img);
Put_Line("Input " & String'Input(Channel));
Next := Next + Period;
end loop;
exception
when E:others => Put_Line("Error: Task Errors");
Put_Line(Exception_Name (E) & ": " & Exception_Message (E));
end Send_Task;
这是我的 node.js 服务器:
require('net').createServer(function (socket) {
console.log("connected");
socket.on('data', function (data) {
console.log(data.toString());
});
socket.on('connection', function(){
console.log("test2");
socket.write("900.0");
});
console.log("test1");
socket.write("900.0");
}).listen(9000);
我的 node.js 服务器的控制台输出:
connected
test1
0.00 //value of Message'Img
Ada 的任务没有输出。似乎任务中的循环已停止并等待来自 node.js 的消息。如果没有 Put_Line("Input " & String'Input(Channel)); 行,一切正常(当然从 node.js 获取消息除外)。
感谢您的帮助!
【问题讨论】:
标签: javascript node.js sockets server ada