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

Crash NSStream #4

Closed
seropunov opened this issue Aug 13, 2014 · 18 comments
Closed

Crash NSStream #4

seropunov opened this issue Aug 13, 2014 · 18 comments

Comments

@seropunov
Copy link

Error if i uses this class

Log:
2014-08-13 22:02:46.079 WebSocket[2937:1803] +[NSStream getStreamsToHostWithName:port:inputStream:outputStream:]: unrecognized selector sent to class 0x3853e86c
2014-08-13 22:02:46.083 WebSocket[2937:1803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSStream getStreamsToHostWithName:port:inputStream:outputStream:]: unrecognized selector sent to class 0x3853e86c'

@daltoniam
Copy link
Owner

what are you passing in for your url? Needs to be in a the standard host + port configuration.
ws://myhost.com:8080

P.S. Might want to wrap your error in a code block, makes it easier to read.

@seropunov
Copy link
Author

Test Xcode 6 Betta 5
Device: iPhone 5,5C,5S(iOS 7.1.2)

This my code:

class Server: NSObject, WebsocketDelegate {
    var                     socket : Websocket!

func initServerConnect() {
        socket = Websocket(url: NSURL.URLWithString("ws://193.169.240.21:9000"))
        socket.delegate = self
        socket.connect()
    }    
    //websocket delegate methods
    func websocketDidConnect() {
        println("websocket is connected")
    }
    func websocketDidDisconnect(error: NSError?) {
        println("websocket is disconnected: \(error!.localizedDescription)")
    }
    func websocketDidWriteError(error: NSError?) {
        println("wez got an error from the websocket: \(error!.localizedDescription)")
    }
    func websocketDidReceiveMessage(text: String) {
        println("got some text: \(text)")
    }
    func websocketDidReceiveData(data: NSData) {
        println("got some data: \(data.length)")

        //self.socket.writeData(data) //example on how to write binary data to the socket
    }
}

All error message

2014-08-14 10:08:42.028 socket[3047:1803] +[NSStream getStreamsToHostWithName:port:inputStream:outputStream:]: unrecognized selector sent to class 0x3853e86c
2014-08-14 10:08:42.031 socket[3047:1803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSStream getStreamsToHostWithName:port:inputStream:outputStream:]: unrecognized selector sent to class 0x3853e86c'
*** First throw call stack:
(0x2d5e8ecb 0x37d83ce7 0x2d5ec703 0x2d5eb0f7 0x2d53a058 0x10b8bc 0x10a408 0x119640 0x11968c 0x3826cd53 0x38272689 0x382728dd 0x3839dc17 0x3839dadc)
libc++abi.dylib: terminating with uncaught exception of type NSException

Thanks.

@daltoniam
Copy link
Owner

Alright code looks fine. What is the websocket server you are trying to connect to? Did you try using the example ruby websocket server in the examples folder? I bet the issue is with the websocket server, as in my testing starscream connected fine to any server that passed autobahn tests.

@seropunov
Copy link
Author

This custom server, if i use SoketRecket(ObjC) all ok. But if i use this class error ((

@daltoniam
Copy link
Owner

Alright, good to know. I am not sure what to do at this point, as my several test servers work fine and I don't have a way to reproduce the issue. If you know of a websockets server that can be used to reproduced the issue, I would be happy to track it down.

@vikingjs
Copy link

I had the same problem; getStreamsToHostWithName is not found on mavericks. I replaced line 154 with

    NSStream.getStreamsToHost(NSHost(name:_url.host), port: _url.port.integerValue, inputStream: &_inputStream, outputStream: &_outputStream)

to run in MacOS X 10.9

@daltoniam
Copy link
Owner

@vikingjs good point and thank you, I didn't consider it was being run on 10.9. It was only designed to work on 10.10 and iOS 8 as I figured Swift was going to be primarily done with new projects going forward. That being said we could probably support older OSes by simply doing a API check before doing the bind or just use the CoreFoundation calls if there is interest.

@vikingjs
Copy link

Probably don't even need an API check for that one; I think NSStream::getStreamsToHost() is universal, and has been there since OSX 10.3. I haven't specifically checked for it in iOS, however.

@daltoniam
Copy link
Owner

True true, doesn't appear to be in iOS though:
https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSStream_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003743

I would prefer if possible not to have to do a iOS/OS X check. Main reason I was drawn to the getStreamsToHostWithName but not sure how widespread 10.9/iOS 7 support in Swift is.

@vikingjs
Copy link

I looked at NSStream.h where it extends getStreamsToHostWithName() and it also has getStreamsToHost().

It's probably a bug in the header that it doesn't check the environment, which is why this problem was so mysterious. The compiler had no problem with the new method call. So your reasoning about Swift is parallel to Apple's - they also see Swift as a forward-only tool. Unfortunately, I'm not in that happy world yet.

At any rate, I think it would be worth testing to see if the older method still works. I'd even bet the new one calls it :).

@daltoniam
Copy link
Owner

Look at the source of instead the documentation, what!?!?! 😄. I just end up using the coreFoundation API as I had already done it in my Objective-C version of this library and I know it works on both platforms. Any questions let me know.

@vikingjs
Copy link

This version works fine for me. Thanks!

@seropunov
Copy link
Author

This version works fine for me to. Thanks!

@daltoniam
Copy link
Owner

Glad to hear it!

@ghost
Copy link

ghost commented Nov 3, 2014

This is a great succinct piece of code. I had no trouble connecting to some test sites. I successfully connected to our server but when I sent a login string, using writeString(), our server developer said the string I sent was broken into 10 byte pieces. I have used socket.io with javascript and had no problems connecting or sending the same string. Any suggestions?

@ghost
Copy link

ghost commented Nov 3, 2014

*writeText() not writeString, sorry.

@ghost
Copy link

ghost commented Nov 3, 2014

oops, commentary closed, too bad :(

@daltoniam
Copy link
Owner

@frankgeonet Glad to hear you like the code! If you found a bug, please open an new issue so we can start dialog on it, as this issue has been resolved. Thanks!

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

3 participants