Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ubuntu support #29

Open
luisdelarosa opened this issue Oct 8, 2017 · 6 comments
Open

Add Ubuntu support #29

luisdelarosa opened this issue Oct 8, 2017 · 6 comments

Comments

@luisdelarosa
Copy link

Swift is used on Ubuntu and MQTT is a good protocol for IoT purposes. This can be used both on the server-side and on Raspberry Pis.

Here is the current error log when built on Ubuntu MATE on Raspberry Pi:

/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSession.swift:90:89: error: '#selector' can only be used with the Objective-C runtime
        keepAliveTimer = Timer(timeInterval: Double(keepAlive), target: self, selector: #selector(MQTTSession.keepAliveTimerFired), userInfo: nil, repeats: true)
                                                                                        ^
/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSessionStreamDelegate.swift:65:19: error: method 'stream(_:handle:)' has different argument names from those required by protocol 'StreamDelegate' ('stream(_:handleEvent:)')
    internal func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
                  ^                         ~~~~~~
                                            handleEvent
Foundation.StreamDelegate:2:17: note: requirement 'stream(_:handleEvent:)' declared here
    public func stream(_ aStream: Foundation.Stream, handleEvent eventCode: Foundation.Stream.Event)
                ^
/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSessionStreamDelegate.swift:34:9: error: type 'Stream' has no member 'getStreamsToHost'
        Stream.getStreamsToHost(withName: host, port: Int(port), inputStream: &inputStream, outputStream: &outputStream)
        ^~~~~~ ~~~~~~~~~~~~~~~~
/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSessionStreamDelegate.swift:43:38: error: cannot convert value of type 'String' to expected argument type 'AnyObject?'
            inputStream?.setProperty(securityLevel, forKey: Stream.PropertyKey.socketSecurityLevelKey)
                                     ^~~~~~~~~~~~~
                                                   as! AnyObject
/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSessionStreamDelegate.swift:44:39: error: cannot convert value of type 'String' to expected argument type 'AnyObject?'
            outputStream?.setProperty(securityLevel, forKey: Stream.PropertyKey.socketSecurityLevelKey)
                                      ^~~~~~~~~~~~~
                                                    as! AnyObject
/home/louie/projects/swift/SwiftMQTT/Sources/SwiftMQTT/MQTTSessionStreamDelegate.swift:95:26: warning: result of call to 'read(_:maxLength:)' is unused
            inputStream?.read(&readByte, maxLength: 1)
                         ^   ~~~~~~~~~~~~~~~~~~~~~~~~~
@luisdelarosa
Copy link
Author

For the #selector error, it looks like alternatives like Perfect's Threading framework is an alternative: https://stackoverflow.com/questions/41328989/swift-3-linux-with-perfect-add-a-scheduled-timer-with-interval-to-the-runloop

@luisdelarosa
Copy link
Author

For the steam(_:handleEvent:) error, I filed a bug with Swift at https://bugs.swift.org/browse/SR-6088
It could also be worked around with #if os() directives.

@luisdelarosa
Copy link
Author

Stream.getStreamsToHost is NSUnimplemented on Ubuntu, due to

// Discussion of this API is ongoing for its usage of AutoreleasingUnsafeMutablePointer

@jiribohm
Copy link

Hi, Would like to ask you, if you have solved the problem with: Stream.getStreamsToHost(withName: host, port: Int(port), inputStream: &inputStream, outputStream: &outputStream) Thanks for your answer!

@tomieq
Copy link

tomieq commented Mar 1, 2021

The problem is stil not solved in 2021. I'm having the same issue on raspberry with swift 5.1.
I wanted to rewrite my smart home logic from python to swift, thus mqtt connection is a must.
Mqtt library uses Stream.getStreamsToHost under the hood, so it looks like it is a dead end to me.

@mickeyl
Copy link

mickeyl commented Apr 2, 2021

Hard to believe that the discussion over the usage of a pointer is holding back a very useful API for several years now. If that API is not available, is there a matching workaround that just returns a tuple?

Obviously it’s not just the autoreleased pointer, the whole CFSocketStream infrastructure is missing on Linux, hence someone needs to come up with a Stream pair that encapsulates POSIX sockets instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants