Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby eventmachine服务器无法执行接收\u数据_Ruby_Eventmachine - Fatal编程技术网

Ruby eventmachine服务器无法执行接收\u数据

Ruby eventmachine服务器无法执行接收\u数据,ruby,eventmachine,Ruby,Eventmachine,我有一个eventmachine应用程序,其中一个脚本从文件中读取数据,逐行向另一个脚本发送数据,“服务器”脚本对该数据执行操作。不幸的是,“服务器”脚本未能按其应有的方式执行接收\u数据。我知道正在建立连接,因为它会切断post_init,并且我知道发送方脚本正在发送数据。下面是我的一些代码以及如何启动服务器 module BT_Server def post_init puts "-- someone connected to the echo server!"

我有一个eventmachine应用程序,其中一个脚本从文件中读取数据,逐行向另一个脚本发送数据,“服务器”脚本对该数据执行操作。不幸的是,“服务器”脚本未能按其应有的方式执行
接收\u数据。我知道正在建立连接,因为它会切断
post_init
,并且我知道发送方脚本正在发送数据。下面是我的一些代码以及如何启动服务器

module BT_Server
    def post_init
        puts "-- someone connected to the echo server!"
    end
    def receive_data(data)
        puts "hi"
        int, time, *int_macs = data.split("-")
        # more stuff that isn't needed here
    end
    def bt_left(dev)
        dev.save
        if t = Device.macs.index(dev.mac)
            Device.all[t].add_int(dev.int, dev.t_0, dev.t_l)
        else
            Device.new(dev.mac, dev.int, dev.t_0, dev.t_l)
        end
        return false
    end
    def unbind
        puts "disconnection"
    end
end

EventMachine::run {
  EventMachine::start_server 'localhost', 8081, BT_Server
  puts t_0 = Time.new
  puts 'listening...'
}

注意:我将模块定义和我的类放在一个单独的文件中,如果这有什么不同的话,我需要将它们放入服务器脚本中。

我测试了您的代码,每次通过telnet发送内容时,它都会输出“hi”。 在我看来,代码是正确的。 您确定发送脚本正在工作吗?尝试在端口8081上使用手动telnet。
问候。

我测试了你的代码,每次我通过telnet发送东西时,它都会输出“hi”。 在我看来,代码是正确的。 您确定发送脚本正在工作吗?尝试在端口8081上使用手动telnet。 问候。

Hmm。似乎无法发送数据。它从来没有出现过任何错误或其他问题。似乎它未能发送数据。它从未出现过任何错误或其他问题。