开发者

eventmachine server failing to execute receive_data

I have an eventmachine app where one script is reading from a file, sending data to another script line by line, and the "server" script is acting upon that data. Unfortunately, the "server" script fails to execute receive_data as it should. I know that a connection is being made because it eecutes post_init, and I know the sender script is sending data. Here is some of my code along with how I start the server.

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)
        开发者_StackOverflow中文版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...'
}

Note: I have the Module definition in a separate file, along with my classes, which I require into the server script, if that makes any difference.


i tested your code and it outputs 'hi' every time i send something via telnet. from my point of view, the code is correct. are you sure the sending script is working? try with a manual telnet on port 8081. regards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜