Giter Site home page Giter Site logo

emqx / cocoamqtt Goto Github PK

View Code? Open in Web Editor NEW
1.6K 78.0 413.0 1.3 MB

MQTT 5.0 client library for iOS and macOS written in Swift

Home Page: https://www.emqx.com/en

License: Other

Swift 99.32% Ruby 0.47% Objective-C 0.16% Shell 0.04%
cocoamqtt swift mqtt ios macos cocoapods mqtt-client tvos macosx

cocoamqtt's Introduction

English | 简体中文 | Русский

EMQX

GitHub Release Build Status Coverage Status Docker Pulls OpenSSF Scorecard Slack Discord Twitter YouTube

EMQX is the world's most scalable open-source MQTT broker with a high performance that connects 100M+ IoT devices in 1 cluster, while maintaining 1M message per second throughput and sub-millisecond latency.

EMQX supports multiple open standard protocols like MQTT, HTTP, QUIC, and WebSocket. It’s 100% compliant with MQTT 5.0 and 3.x standard, and secures bi-directional communication with MQTT over TLS/SSL and various authentication mechanisms.

With the built-in powerful SQL-based rules engine, EMQX can extract, filter, enrich and transform IoT data in real-time. In addition, it ensures high availability and horizontal scalability with a masterless distributed architecture, and provides ops-friendly user experience and great observability.

EMQX boasts more than 20K+ enterprise users across 50+ countries and regions, connecting 100M+ IoT devices worldwide, and is trusted by over 400 customers in mission-critical scenarios of IoT, IIoT, connected vehicles, and more, including over 70 Fortune 500 companies like HPE, VMware, Verifone, SAIC Volkswagen, and Ericsson.

For more information, please visit EMQX homepage.

Get Started

Run EMQX in the Cloud

The simplest way to set up EMQX is to create a managed deployment with EMQX Cloud. You can try EMQX Cloud for free, no credit card required.

Run EMQX using Docker

docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:latest

Next, please follow the Deploy with Docker guide for further instructions.

Run EMQX cluster on Kubernetes

Please consult official EMQX Operator documentation for details.

Run EMQX on macOS

EMQX is available as core Homebrew package.

brew install emqx
emqx start

More installation options

If you prefer to install and manage EMQX yourself, you can download the latest version from www.emqx.io/downloads.

For more installation options, see the EMQX installation documentation.

Documentation

The EMQX documentation is available at www.emqx.io/docs/en/latest/.

The EMQX Enterprise documentation is available at docs.emqx.com/en/.

Contributing

Please see our contributing.md.

For more organised improvement proposals, you can send pull requests to EIP.

Get Involved

Resources

  • MQTT client programming

    A series of blogs to help developers get started quickly with MQTT in PHP, Node.js, Python, Golang, and other programming languages.

  • MQTT SDKs

    We have selected popular MQTT client SDKs in various programming languages and provided code examples to help you quickly understand the use of MQTT clients.

  • MQTTX

    An elegant cross-platform MQTT 5.0 client tool that provides desktop, command line, and web to help you develop and debug MQTT services and applications faster.

  • Internet of Vehicles

    Build a reliable, efficient, and industry-specific IoV platform based on EMQ's practical experience, from theoretical knowledge such as protocol selection to practical operations like platform architecture design.

Build From Source

The master branch tracks the latest version 5. For version 4.4 checkout the main-v4.4 branch.

EMQX 4.4 requires OTP 24. EMQX 5.0 ~ 5.3 can be built with OTP 24 or 25. EMQX 5.4 and newer can be built with OTP 25 or 26.

git clone https://github.com/emqx/emqx.git
cd emqx
make
_build/emqx/rel/emqx/bin/emqx console

For 4.2 or earlier versions, release has to be built from another repo.

git clone https://github.com/emqx/emqx-rel.git
cd emqx-rel
make
_build/emqx/rel/emqx/bin/emqx console

License

See LICENSE.

cocoamqtt's People

Contributors

1989allen126 avatar adicatur avatar alexyu1989 avatar amsibsam avatar andypiper avatar cyrusingraham avatar dahuayuan avatar filippocamillotexa avatar hjianbo avatar hsoi avatar karinberg avatar leeway1208 avatar manucheri avatar massi-ang avatar michalsrutek avatar mindaugasjucius avatar nobre84 avatar nrbrook avatar omkar-sharechat avatar orbitbot avatar petrpavlik avatar przemyslaw-szurmak avatar ptescher avatar sotpt avatar spinnerok avatar stansidel avatar swilder-m avatar tynox avatar xandrefreire avatar zhihuitang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocoamqtt's Issues

Running the example project fails

I downloaded and ran the example project on an iPhone 5. But it fails with the following error.

dyld: Library not loaded: @rpath/CocoaAsyncSocket.framework/CocoaAsyncSocket
Referenced from: /private/var/containers/Bundle/Application/F1106E5F-A377-49BC-B09D-5BB5BDB4FD0D/Example.app/Frameworks/CocoaMQTT.framework/CocoaMQTT
Reason: image not found

Cannot build watchOS and OSX schemes

I tried to build all the schemes of the project to get it ready for Carthage. But I couldn't do that for two of the schemes: watchOS and OSX.

There's an error for the watchOS target:

/Users/user/Projects/CocoaMQTT/Source/CocoaMQTT.swift:291:32: Use of unresolved identifier 'kCFStreamSSLPeerName'

And another one for OSX:

/Users/user/Projects/CocoaMQTT/Source/CocoaMQTT.swift:284:33: Value of type 'GCDAsyncSocket' has no member 'enableBackgroundingOnSocket'

As I don't need those schemes for my project now I didn't go deep into those errors. But I think it's important to state them here. I used Xcode Version 7.2.1 (7C1002) for building. There'd been no changes made to the project prior to building.

No IOS 7 support

Hi Guys,

First, thanks for building a neat Swift MQTT lib!
But is it really necessary to set the minimum IOS version to 8.0? There are still a lot of projects out there that support IOS 7. Of course, nobody wants to but there really are still some users out there. In our case, still 6% of all IOS users have IOS 7.x

I would be very grafeful if you could take a look and maybe decide to support 7.0
Otherwise I have to use a different (ObjC) lib.

Have a nice day!

Crash if server returns reserved CONNACK message

Background:
AdafruitIO has extended the MQTT protocol by adding two additional CONNACK return codes:

6: Connection Refused, throttled
7: Connection Refused, banned

https://io.adafruit.com/blog/mqtt/2016/06/28/extending-the-mqtt-protocol/

Under normal circumstances, these codes shouldn't come up. However, I have engineered my code to reconnect after a slight delay on disconnection. Due to #98 this code currently is being triggered frequently, leading to AdafruitIO throttling further connections.

Issue:
When the server returns a CONNACK message with a code other than the formally defined 0-5 (
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718033 ), CocoaMQTT crashes in CocoaMQTT.didReceiveConnAck(reader:, connack:) at:

let ack = CocoaMQTTConnAck(rawValue: connack)!

The initializer for CocoaMQTTConnAck returns nil when passed a rawValue outside 0...5.

`fatal error: unexpectedly found nil while unwrapping an Optional value
2016-10-20 17:12:14.708461 Ahem[1782:42159] fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0    libswiftCore.dylib                 0x0000000100458580 swift_reportError + 132
1    libswiftCore.dylib                 0x0000000100475850 _swift_stdlib_reportFatalError + 61
2    libswiftCore.dylib                 0x0000000100271550 specialized specialized StaticString.withUTF8Buffer ((UnsafeBufferPointer) -> A) -> A + 355
3    libswiftCore.dylib                 0x00000001003e9600 partial apply for (_fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x0000000100271550 specialized specialized StaticString.withUTF8Buffer ((UnsafeBufferPointer) -> A) -> A + 355
5    libswiftCore.dylib                 0x00000001003a4970 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never + 96
6    CocoaMQTT                          0x00000001001b64e0 CocoaMQTT.didReceiveConnAck(CocoaMQTTReader, connack : UInt8) -> () + 149
7    CocoaMQTT                          0x00000001001b86d0 protocol witness for CocoaMQTTReaderDelegate.didReceiveConnAck(CocoaMQTTReader, connack : UInt8) -> () in conformance CocoaMQTT + 76
8    CocoaMQTT                          0x00000001001ba7c0 CocoaMQTTReader.frameReady() -> () + 440
9    CocoaMQTT                          0x00000001001ba220 CocoaMQTTReader.payloadReady(Data) -> () + 1403
10   CocoaMQTT                          0x00000001001b5250 CocoaMQTT.socket(GCDAsyncSocket, didRead : Data, withTag : Int) -> () + 4089
11   CocoaMQTT                          0x00000001001b62b0 @objc CocoaMQTT.socket(GCDAsyncSocket, didRead : Data, withTag : Int) -> () + 95
12   CocoaAsyncSocket                   0x0000000100133900 __37-[GCDAsyncSocket completeCurrentRead]_block_invoke + 83
13   libdispatch.dylib                  0x0000000100aac741 _dispatch_call_block_and_release + 12
14   libdispatch.dylib                  0x0000000100aa2fc4 _dispatch_client_callout + 8
15   libdispatch.dylib                  0x0000000100ab1a71 _dispatch_main_queue_callback_4CF + 362
16   CoreFoundation                     0x00007fff9eca9c80 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
17   CoreFoundation                     0x00007fff9ec6a810 __CFRunLoopRun + 2205
18   CoreFoundation                     0x00007fff9ec6a410 CFRunLoopRunSpecific + 420
19   HIToolbox                          0x00007fff9e20be7c RunCurrentEventLoopInMode + 240
20   HIToolbox                          0x00007fff9e20bbf1 ReceiveNextEventCommon + 432
21   HIToolbox                          0x00007fff9e20bb8f _BlockUntilNextEventMatchingListInModeWithFilter + 71
22   AppKit                             0x00007fff9c9021b0 _DPSNextEvent + 1093
23   AppKit                             0x00007fff9d012286 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1637
24   AppKit                             0x00007fff9c8f6c1f -[NSApplication run] + 926
25   AppKit                             0x00007fff9c8c15b5 NSApplicationMain + 1237
26   Ahem                               0x0000000100027750 main + 84
27   libdyld.dylib                      0x00007fffb3caa254 start + 1
`

It would be nice (and more future-safe as MQTT evolves) if CocoaMQTT could handle reserved values more gracefully. There may be other instances of this class of issue besides CONNACK.

Message ID

We encountered a bug with your _nextMessageId() function.
When it reaches the max value the whole app crashes.
We fixed this bug with rewriting your code:

CocoaMQTT.swift

func _nextMessageId() -> UInt16 {
        if amid == UInt16.max {
            amid = 0
        }
        amid += 1
        return amid
    }

Fails to compile in Swift 1.2

A number of issues e.g. unknown type of Byte, and some ambiguous operators e.g. += - also implicit type conversions and other problems. Working on a patch.

The delegate of publish message

The delegate of publish message is from client, not from server. How can figure out the message state? did server received or not?

Runtime error when it receives empty messages

When CocoaMQTT receives an empty messages it generates a runtime error on:

payload = [UInt8](data![pos...end])

In CocoaMQTTFramePublish:

    func unpack() {
        //topic
        var msb = data![0], lsb = data![1]
        let len = UInt16(msb) << 8 + UInt16(lsb)
        var pos: Int = 2 + Int(len)
        topic = NSString(bytes: [UInt8](data![2...(pos-1)]), length: Int(len), encoding: NSUTF8StringEncoding) as? String

        //msgid
        if qos == 0 {
            msgid = 0
        } else {
            msb = data![pos]; lsb = data![pos+1]
            msgid = UInt16(msb) << 8 + UInt16(lsb)
            pos += 2
        }
        //payload
        let end = data!.count - 1

        payload = [UInt8](data![pos...end])
    }

Improvement: very long compile times on CocoaMQTTFrame.data()

Hi,

depending on your project philosophy this may be a non-issue (so feel free to close it), but with current Swift compiles we noticed that CocoaMQTTFrame.swift, func data() -> [UInt8](lines 159ff) take an exceptional amount of compile time (on my local machine about 10 seconds).

I think this is about the same issue (array concatenation) as mentioned in https://twitter.com/benjaminencz/status/685510563015741440 for example, the compile times can be easily reproduced as described in http://irace.me/swift-profiling

If you choose to accommodate this compiler issue, refactoring this method avoiding the plus operation on the array may remedy this issue and improve compile times considerably :-)

About VIOP problem

Now, this framework is support VOIP and socket can keep connecting with server. But the didReceivedMessage delegate didn't response. When the app come back forground, then the delegate be called. It's not immediate.

Support IPv6 with non-standart port Issue

Hi, I have some issues trying to connect to my mqtt server with a domain name that returns an IPv4, and GCDAsyncSocket cant digest over an IPv6 network. I ran step by step to tried to figured out what's happened, and I think that maybe it is because I use an numeric port and the "getaddrinfo" cant resolve it.

Can you help me with this issue please, my app was rejected by Apple because of this.

Thanks in advance.

Swift 2.3

Is there a version to use CocoaMQTT with Swift 2.3? As far as I can tell, the current version only works for Swift 3.0 right?

no such moudle ’CocoaAsyncSocket

follow this step
$ git init
Add CocoaMQTT as a git submodule by running the following command:
$ git submodule add https://github.com/emqtt/CocoaMQTT.git

CocoaPods

Install using CocoaPods by adding this line to your Podfile:

use_frameworks! # Add this if you are targeting iOS 8+ or using Swift
pod 'CocoaMQTT'
Then, run the following command:

$ pod install
Last, creat a CocoaMQTT-Bridging-Header.h file in your project, in which add the following line:

import "CocoaMQTT/CocoaMQTT.h"

xcode 7.2
//
// CocoaMQTT.swift
// CocoaMQTT
//
// Created by Feng [email protected] on 14/8/3.
// Copyright (c) 2015 emqtt.io. All rights reserved.
//

import Foundation
import CocoaAsyncSocket --- no such moudle ’CocoaAsyncSocket ‘

import MSWeakTimer

CocoaMQTT Memory Leak?

Mail from Stolarski:

I’m using your library for the last few months, and In the last few days I’m trying to trace a memory leak in my app, which I believe is coming from the mqtt publisher.

When I’m looking at the memory allocations using apple’s leaks instrumentation tool, I can see a ContiguousArrayStorage is being allocated each time a message is being sent. This array doesn’t seem to be released during the app life, and because my app send messages every few minutes, it ends with ~600Kb being allocated every 2-3 minutes, which causes the app to crash eventually after few hours/days.

Error in connecting to socket

I am trying to connect a host with url tcp://172...** with port ***. but i am getting error 8 - "nodename nor servname provided, or not known". Please help.

Retained Messages

Is it possible to set the retained bit of of a published message to true?

It does't look look the the publish call includes a retained option.

Fails to compile in XCODE 6.4

Hello,

The code fails to compile in Xcode 6.4 with 19 errors all of which are in the file "CocoaMQTT.swift":

  • "Use of undeclared type 'GCDAsyncSocketDelegate'"
  • "Use of unresolved identifier 'GCDAsyncSocket'"
  • "'CocoaMQTT' does not have a member named 'socket'"
  • "'CocoaMQTTReader' does not have a member named 'socket'"

Any idea how to solve this?
EDIT: nvm solved it.

Making `subscriptions` public

It would be nice if a client could track its subscriptions.
Better still, subscribing to already subscribed topics could be sort of a no-op with maybe an option for forced subscribe.

Currently, I'm doing this using a Set and the didSubscribeTopic & didUnsubscribeTopic callbacks.
Is there any plan to support this?

CocoaMQTT does not work with moquette and HiveMQ on IOS

Hello

It seems like CocoaMQTT does not send standard messages. I tested it with 2 mqtt brokers and I got the some no response. Here it is what I did.

I wrote this code (that is basically the same code in main.swift):

    let mqtthost = "10.0.0.10" // the ip address of the mqtt broker.
    let mqttCli = CocoaMQTTCli()
    let clientIdPid = "CocoaMQTT-" + String(NSProcessInfo().processIdentifier)
    let mqtthost = "24.25.1.31"
    let mqtt = CocoaMQTT(clientId: clientIdPid, host: mqtthost, port: 1883)
//    mqtt.username = "test"
//    mqtt.password = "public"
    mqtt.willMessage = CocoaMQTTWill(topic: "/will", message: "dieout")
    mqtt.keepAlive = 90
    mqtt.delegate = mqttCli
    let connected = mqtt.connect()
    NSLog("Connected \(connected)")
    mqtt.subscribe("/a/b/c", qos: CocoaMQTTQOS.QOS1)
    mqtt.publish("/a/b/c", withString: "Qos0 Msg", qos: CocoaMQTTQOS.QOS0)
    mqtt.publish("/a/b/c", withString: "Qos1 Msg", qos: CocoaMQTTQOS.QOS1)
    mqtt.publish("/a/b/c", withString: "Qos2 Msg", qos: CocoaMQTTQOS.QOS2)
    mqtt.ping()

Client console output is:

Hello, CocoaMQTT!
2015-10-18 13:21:36.075 thought you[20155:1236000] Connected true
didPublishMessage to /a/b/c
didPing

The IOS application never receives messages. It could send but they are never published. I launched a moquette broker instance on localhost. Here is mqtt output:


  ___  ___                       _   _        ___  ________ _____ _____  
  |  \/  |                      | | | |       |  \/  |  _  |_   _|_   _| 
  | .  . | ___   __ _ _   _  ___| |_| |_ ___  | .  . | | | | | |   | |   
  | |\/| |/ _ \ / _\ | | | |/ _ \ __| __/ _ \ | |\/| | | | | | |   | |   
  | |  | | (_) | (_| | |_| |  __/ |_| ||  __/ | |  | \ \/' / | |   | |   
  \_|  |_/\___/ \__, |\__,_|\___|\__|\__\___| \_|  |_/\_/\_\ \_/   \_/   
                   | |                                                   
                   |_|                                                   

0    [main] INFO  Server  - Using config file: /Users/pablo/Downloads/distribution-0.7-bundle-tar/config/moquette.conf
5    [main] INFO  Server  - Persistent store file: /Users/pablo/Downloads/distribution-0.7-bundle-tar/bin/moquette_store.mapdb
174  [main] INFO  FileAuthenticator  - Loading password file: /Users/pablo/Downloads/distribution-0.7-bundle-tar/config/password_file.conf
405  [main] INFO  NettyAcceptor  - Server binded host: 0.0.0.0, port: 1883
408  [main] INFO  NettyAcceptor  - Server binded host: 0.0.0.0, port: 8080
Server started, version 0.7
7401 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type SUBSCRIBE
7402 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PUBLISH
7402 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PUBLISH
7402 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PUBLISH
7403 [pool-1-thread-1] ERROR SimpleMessaging  - Serious error processing the message org.eclipse.moquette.proto.messages.SubscribeMessage@7517ce04 for session [clientID: null]org.eclipse.moquette.server.netty.NettyChannel@30155ec2
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.eclipse.moquette.spi.impl.AnnotationSupport.dispatch(AnnotationSupport.java:66)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:173)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:62)
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.moquette.spi.impl.AnnotationSupport.dispatch(AnnotationSupport.java:64)
    ... 6 more
Caused by: java.lang.NullPointerException
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.processSubscribe(ProtocolProcessor.java:606)
    ... 11 more
7412 [pool-1-thread-1] INFO  ProtocolProcessor  - PUBLISH from clientID <null> on topic </a/b/c> with QoS MOST_ONE
7413 [pool-1-thread-1] INFO  ProtocolProcessor  - PUBLISH from clientID <null> on topic </a/b/c> with QoS LEAST_ONE
7406 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
7424 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type CONNECT
7495 [pool-1-thread-1] ERROR ProtocolProcessor  - 
java.lang.RuntimeException: Can't find a ConnectionDescriptor for client null in cache {}
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.sendPubAck(ProtocolProcessor.java:476)
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.executePublish(ProtocolProcessor.java:324)
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.processPublish(ProtocolProcessor.java:301)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.moquette.spi.impl.AnnotationSupport.dispatch(AnnotationSupport.java:64)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:173)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:62)
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
7498 [pool-1-thread-1] INFO  ProtocolProcessor  - PUBLISH from clientID <null> on topic </a/b/c> with QoS EXACTLY_ONCE
7501 [pool-1-thread-1] ERROR SimpleMessaging  - Serious error processing the message org.eclipse.moquette.proto.messages.PublishMessage@341cb737 for session [clientID: null]org.eclipse.moquette.server.netty.NettyChannel@72bcc5ea
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at org.eclipse.moquette.spi.impl.AnnotationSupport.dispatch(AnnotationSupport.java:66)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:173)
    at org.eclipse.moquette.spi.impl.SimpleMessaging.onEvent(SimpleMessaging.java:62)
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.moquette.spi.impl.AnnotationSupport.dispatch(AnnotationSupport.java:64)
    ... 6 more
Caused by: java.lang.NullPointerException
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.sendPubRec(ProtocolProcessor.java:459)
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.executePublish(ProtocolProcessor.java:330)
    at org.eclipse.moquette.spi.impl.ProtocolProcessor.processPublish(ProtocolProcessor.java:301)
    ... 11 more
7517 [pool-1-thread-1] INFO  ProtocolProcessor  - cleaning old saved subscriptions for client <CocoaMQTT-20155>
7533 [pool-1-thread-1] INFO  ProtocolProcessor  - Create persistent session for clientID <CocoaMQTT-20155>
7573 [pool-1-thread-1] INFO  ProtocolProcessor  - Connected client ID <CocoaMQTT-20155> with clean session true
97566 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
187576 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
277573 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
367575 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
457575 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ
547579 [nioEventLoopGroup-3-1] INFO  NettyMQTTHandler  - Received a message of type PINGREQ

Make CLI more useful / configurable

Right now, the sample code uses hard coded values. Would be helpful to make it into a more generic pub/sub utility using command-line parameters. Working on improving this.

SSL connection with RabbitMQ

Hi all
Did you ever try to connect this MQTT client to a rabbitMQ instance using SSL?
I'm having a hard time doing so, maybe you have some suggestions
Here's the code I'm using:

    mqttClient = CocoaMQTT(clientId: "client", host: host, port: 8883)
    mqttClient?.secureMQTT = true
    mqttClient?.username = username
    mqttClient?.password = password
    mqttClient?.keepAlive = 90
    mqttClient?.delegate = self
    mqttClient?.connect()

This results in this error:

Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}

The endpoint is working correctly, other clients (written in other languages) are working fine.
I was able to connect using ckrey/MQTT-Client-Framework, but I rather use this library instead :)

import CocoaMQTT dont work

i'am using xcode 8.1 and Swift 10.1.
i did pod install and i it was installed la version 1.0; Is it correct ?
Well, when i put the import CocoaMQTT at code, the xcode say No Such Module.

What is happening ?

Thanks

Why do you have another libraries in sandbox

Why you don't use it as dependency? I have a few frameworks which works with GCDAsynchSocket. And I have a problems when I use these libraries in one project. Can you add it as CocoaPod dependency?

Unable to connect

I have a MQTT over WebSocket host with NodeRed. I am using this library in order to connect but I am getting the following error:

Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}

Code:
let clientIdPid = "CocoaMQTT-" + String(NSProcessInfo().processIdentifier)
let mqtt = CocoaMQTT(clientId: clientIdPid, host: "95.177.135.232", port: 9001)
mqtt.cleanSess = true
mqtt.keepAlive = 60
mqtt.delegate = self
mqtt.connect()

Assertion Causes Crash?

Inside CocoaMQTT.swift, in the frameReady() function, on the switch function if the frameType is undetermined there is a force crash with assert(false).

My app is sometimes crashing on this (I can't figure out what's causing this as it does not happen all the time).

I'm not sure if this is an issue with the library or my implementation, do you have any thoughts on this?

Other than this issue, the MQTT library seems to be working perfectly.

two or more connections management

HI, could you please help with issue:

If I created 2 or more connections, how I can stop specific session ?
Maybe I can specify for example - mqtt!."Some unique identifier like a clientId or port".disconnect() ?

Message payload truncated

When receiving messages (from e.g. mosquitto_pub), the first two characters of the message body are being lost. Messages sent from another CocoaMQTT client are received intact.

Using the framework of the mistakes in the oc

1.Install CocoaMQTT using CocoaPods
2.Choose the OC project
3.Choose the project name in the TARGETS list
4.Click the Build Settings tab
5.In the Build Options section, make sure the option Embedded Content Contains Swift Code is YES, and Defines Module is YES
6.Now, you can import CocoaMQTT framework into any Objective-C .m like: @import CocoaMQTT;

According to the above method in the oc use this frame the following mistakes,How to solve?
2016-03-07 10 14 09

Carthage update fails

Hi,
I've been trying to integrate CocoaMQTT with my project. Carthage update fails. Use Legacy Swift Language Version flag needs to be set to YES.

Disconnect on bad connection

I don't know if there is a bug or just a misunderstanding by my part.
When I connect over a bad 3G signal, in a while it stops receiving answers from ping ("pong").
In my opinion it should fire mqttDidDisconnect.
Is my understanding correct, or I have to implement a way to check that?

Resending messages which never received a PubAck

Currently it looks like when messages are given qos > 0, they are persisted in a Dictionary field named messages

https://github.com/emqtt/CocoaMQTT/blob/master/Source/CocoaMQTT.swift#L228-L242

This field is private and appears to be used for this and some QOS2 related concerns. However, as far as I can tell there isn't a mechanism to attempt to retry sending these messages, and since the field is private there isn't a way for users to do this in their apps.

Would it make sense to make the messages field public so that users could A. resend messages and B. show the status of messages to users?

Error when subscribing to multiple topics

You should either make connState property public so a dev could check if already connected. If not here are the steps I took to get to the error below

  1. We have a few topics
  2. When I subscribe to first topic everything works
  3. When I want to subscribe to another topic. I am assuming that it automatically disconnects from the first topic internally because I stop receiving messages and start receiving messages from new inserted topic
  4. Now if I try to connect to that first topic I get the error message below crash.

I would disconnect to the first topic if connState was available.

assertion failed: : file /Pods/CocoaMQTT/Source/CocoaMQTT.swift, line 581

does this framework support VOIP protocol?

When i push the home button of iPhone, app goes to background and the socket connection is closed. IOS support VIOP background module. APP use this module, IOS system can take over the socket connection when APP goes to background. When socket reveive something, IOS system wake app up for a moment to do with it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.