njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

Failed to read byte from socket(MQTT::ProtocolException) #64

Closed arjayx closed 9 years ago

arjayx commented 9 years ago

hi please @michaelklishin would can help me. I have problems with a mqtt client but not happen with amqp client, I use a broker rabbitmq. my stage are three pc in a network lan

This error with mqtt client

railpc@railpc-VirtualBox:/media/sf_ProjectRubyLinux/Ruby/Semillero$ ruby producer_mqtt.rb 
=> Published Message mqtt sended @ 1430402156 
/home/railpc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mqtt-0.3.1/lib/mqtt/packet.rb:283:in `read_byte': Failed to read byte from socket (MQTT::ProtocolException)
    from /home/railpc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mqtt-0.3.1/lib/mqtt/packet.rb:31:in `read'
    from /home/railpc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mqtt-0.3.1/lib/mqtt/client.rb:454:in `receive_packet'
    from /home/railpc/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mqtt-0.3.1/lib/mqtt/client.rb:283:in `block in connect'

The code of mqtt client :

require "mqtt"

c = MQTT::Client.connect(
  host: '192.168.1.5', 
  port: 1883,
  username: 'guest',
  password: 'guest')

loop do
  m = "Message mqtt sended @ #{Time.now.to_i} " 
  c.publish("builds", m)
  puts "=> Published #{m}"
  sleep 0.2
end
The broker have is configuration in rabbitmq.config :
[
 {rabbit, [
        %%=====================================
        %%----Configuration of AMQP protocol----
        %% =====================================

        {tcp_listeners, [{"192.168.1.5", 5672}]},
        {default_user, <<"guest">>},
        {default_pass, <<"guest">>},
        {default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
        {default_vhost, <<"/">>},
        {loopback_users, []}
 ]},
        %%-----------------------------------------------------

        %%======================================
        %%----Configuration Of MQTT protocol----
        %%======================================
 {rabbitmq_mqtt,[
        {vhost,<<"semillero">>},
        {default_user, << "guest">>},
        {default_pass, <<"guest">>},
        {exchange, <<"amp.topic">>},
        {tcp_listeners,[{"192.168.1.5", 1883}]},
        {allow_anonymous, true}

 ]}
        %%-----------------------------------------------------
].

sorry to my english. thanks @michaelklishin :+1:

njh commented 9 years ago

Duplicate of #63