Code Monkey home page Code Monkey logo

starscream's People

Contributors

abeansits avatar abizern avatar acmacalister avatar cnliusen avatar daltoniam avatar delba avatar dependabot[bot] avatar dreymonde avatar fassko avatar fjcaetano avatar hishnash avatar jnross avatar lbanders avatar lukkas avatar maherksantina avatar mininny avatar moogle19 avatar mqshen avatar muniekmg avatar nicoodeimos avatar noremac avatar nuclearace avatar psahgal avatar pvzig avatar rastersize avatar ricardopereira avatar thbaja avatar thebehera avatar tomaslinhart avatar turbulem 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

starscream's Issues

Delegate methods not being called

The socket part of the library is all working great but the methods implemented as part of the WebSocketDelegate protocol never seem to get called. I think I've tracked this down to the fact that I'm not managing to successfully pass a delegate to the socket.

Here is my code currently:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let client = ClientSocket()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

class ClientSocket {
    let socket: WebSocket

    init() {
        var urlString = "ws://....etc"

        socket = WebSocket(url: NSURL(string: urlString)!)
        let delegate = ClientSocketDelegate()
        socket.delegate = delegate
        socket.connect()
    }
}

class ClientSocketDelegate: WebSocketDelegate {    
    func websocketDidConnect() {
        println("Connected")
    }

    func websocketDidDisconnect(error: NSError?) {
        println("Websocket is disconnected: \(error!.localizedDescription)")
    }

    func websocketDidWriteError(error: NSError?) {
        println("We got an error from the websocket: \(error!.localizedDescription)")
    }

    func websocketDidReceiveData(data: NSData) {
        println("Data")
        println(data)
    }

    func websocketDidReceiveMessage(text: String) {
        println("Text")
        println(text)
    }
}

The socket is being opened correctly and shows up as connecting on the socket side of things, but the delegate method never gets called. I've followed it through the Starscream Websocket.swift file and all of the data gets through successfully until the line self.delegate?.websocketDidConnect() where the delegate always seems to be nil.

Any ideas?

Crash NSStream

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'

How to use it with iOS 7?

"embedded dylibs/frameworks are only supported on iOS 8.0 and later"
I think via source code directly? Please add update readme in that case.

cpu 100% usage when web service is not reachable.

I've found that startscream hangs cpu with "while(isRunLoop)" loop in line 203.
This happens when web service is not available (basically I terminate web process).

I think this is because code "isRunLoop = false" in method disconnectStream is executed before "isRunLoop = true" in initStreamsWithData.

I've moved "isRunLoop = true" 2 lines up before "outputStream!.write()" call and it works as expected.
Maybe it is even safer to put "isRunLoop = true" before outputStream!.open()?

app in the background

I'm using a nodejs primus server with faye.

Everything is working, except for one thing.
Keeping the connection open when the app is on the background (the user is at the home screen)

I want to keep it open, so I can send a notification or something else to it.
Do you have the same problem ?
Or can you send messages to it, when the app is in the background ?

the 600 is 10 minutes, and can't be lower...

UIApplication.sharedApplication().setKeepAliveTimeout(NSTimeInterval(600.0)) { () -> Void in
println("send ping")
self.socket.writeData(NSData(bytes: [1] as [Byte], length: 1))
}

websocketDidWriteError not used

It seems that the delegate method websocketDidWriteError isn't used (nor called) across the whole WebSocket.swift implementation.
To avoid confusion and missing features, it should be removed from the WebSocketDelegate protocol declaration.
Another option would be to mark it as optional (since it is currently mandatory to be implemented in delegate object but never called) but this wouldn't solve the 'missing feature' issue.
What do you think?

Library not found error

Hello,

The library is working fine in simulator but in iPad it gives an error.

"dyld: Library not loaded: @rpath/Starscream.framework/Starscream
Referenced from: /private/var/mobile/Containers/Bundle/Application/425E8195-885B-4935-8E5B-016BD0B9BDEA/Home Automation Sys Swift.app/Home Automation Sys Swift
Reason: image not found"

We have already tried the solutions in the following URL.
http://stackoverflow.com/questions/24002836/dyld-library-not-loaded-rpath-libswift-stdlib-core-dylib

Please help?

Naming Events

In the Swift app, how do I name events and pass data along with them? I only see "ws.onmessage" in the Rails server and socket.writeString("hello there!") in the Swift app.

.

.

set headerWSProtocolValue?

I'm writing an app that uses the WAMP protocol over the socket. I had to modify my version of your code to replace "chat, superchat" (I think that's what it was) with "wamp".

It would be nice if that was configurable on init or the delegate could provide it.

Undeclared type 'WebsocketDelegate'

Trying out starscream for the first time, but xcode is giving me trouble (6.1). On line 4 (the one that starts with 'class leadViewController') I get "Use of undeclared type 'WebsocketDelegate'".

import UIKit
import Starscream

class leadViewController: UIViewController, WebsocketDelegate {

    var socket = WebSocket(url: NSURL(scheme: "ws", host: "192.168.2.56:1337", path: "/")!)

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        socket.delegate = self
        socket.connect()
    }

    func websocketDidConnect() {
        println("websocket is connected")
    }

    func websocketDidDisconnect(error: NSError?) {
        println("websocket is disconnected: \(error!.localizedDescription)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

Share schemes and add a tag for the current project state (Carthage support)

Hey! I was looking to use this in a new all-Swift project, and I was also going to use Carthage to manage its dependencies. It looks like this repo is missing just a few things that would allow it to support that:

  • Share the schemes in the Xcode project, particularly the iOS and Mac ones but sharing the test scheme would also allow you to set up Travis in the future.
  • Create a tag for the current release (after sharing the schemes).

I know you can't support every dev tool out there, but I think these two changes have some other beneficial effects too.

Set a timeout

Sometimes a certain timeout for connection attempts is needed. Having a function to set the timeout of websocket be a good functionality.

set timeout if nothing receives within 10 sec

Hi,

first of all I have to say nice framework.
I would like to know if I can set a timeout which shows me an error message. E.g. I send a string via websocket and wait for response. If nothing receives within 10 seconds I would like to show a message "Connection failed." or "Server unreachable". Can you help me at this point :D?

Thanks and best regards

I could not accept self-signed certificates

I solved adding to WebSocket.swift this code:

if url.scheme == "wss" || url.scheme == "https" {
inputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL,
forKey: NSStreamSocketSecurityLevelKey)
outputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL,
forKey: NSStreamSocketSecurityLevelKey)

        /* Added code */
        var settings = Dictionary<NSObject, NSObject>()
        settings[kCFStreamSSLValidatesCertificateChain] = NSNumber(bool:false)
        settings[kCFStreamSSLPeerName] = kCFNull

        CFReadStreamSetProperty(self.inputStream, kCFStreamPropertySSLSettings, settings)
        CFWriteStreamSetProperty(self.outputStream, kCFStreamPropertySSLSettings, settings)
        /* End Added code*/

    }

Invalid http upgrade

Hi,
I'm trying to connect to a socket but I get the following error:

websocket did disconnectError Domain=Websocket Code=1 "Invalid HTTP upgrade" UserInfo=0x7f83a8d11800 {NSLocalizedDescription=Invalid HTTP upgrade}

I try to connect using the following code:

var socket = WebSocket(url: NSURL(scheme: "http", host: "localhost:8080", path: "/socket")!)
socket.delegate = self
socket.connect()

Any idea what the problem is or what causes this error?
Thanks in advance!

Trying on Beta 5 and running into issues

I'm trying to use this on beta 5 and I'm running into a bunch of issues.

First UnsafeMutablePointer was undefined, so I changed that to UnsafePointer.

Then last was undefined on Array. So I implemented that with:

extension Array {
var last: T {
return self[self.endIndex - 1]
}
}

At which point I ran into issues with converting Websocket.WSResponse to a native object.

So... I figured I'd come back to the source and see if you have had any success with beta 5. Or if I just need to change some compiler options, or what not.

Thanks for any help.

EXC_BAD_ACCESS when receiving large messages

Starscream cannot process messages larger than 65536 characters.

Steps to reproduce:

  1. Run nodejs ws server comprised of the following:

    var WebSocketServer = require('ws').Server,
        wss = new WebSocketServer({port: 8080 });
    
    wss.on('connection', function connection(ws) {
        ws.send(Array(65537).join('a'));
    });
    
  2. Connect to server using Starscream

  3. Crash should be triggered:

    EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address={{ *address removed* }} )
    

Auto reconnect

Hello,

It is possible to automatically reconnect if the socket is disconnected ?

thk's

websocket disconnected: masked and rsv data is not currently supported

I am using Loxone Miniserver , and your awesome Library for websockets (i.e starscream). its working fine. I connect to miniserver , also Im sending the Commands to my miniserver via writeString("my_command") method. Im getting a little issue, after some idle time im getting this error msg "websocket disconnected: masked and rsv data is not currently supported" How to resolve this.

and is there any way to reconnect the socket existing object. I first Connect my socket in the AppDelegate, then Im using this in my whole app.

How to reconnect the existing object of my socket in certain ViewController. please help

Proofread README.md

  • "See the Installation instructions, on how..." Unnecessary comma.
  • "After you are connected, we some delegate methods we need to implement." Word missing.

Demo app

Great work Dalton.

Perhaps add a demo app.

socket writeString problem

I have modified your sample to connect to our server and send a login string.

The websocket successfully connects to our server:

var socket = Websocket(url: NSURL(scheme: "ws", host: "ourhost_url:8080", path: "/")!, protocols: ["our_protocol"])
.
.
.
socket.connect()
.
.
.
Once connected, our server expects a json string which I send like this:
.
.
.
let myConnect = "{'cmd':'connect','target':'@2.1.1.1','params':{'password':'my_password','mode':'my_mode'}}"
socket.writeString(myConnect)
.
.
.
The server receives this string but it is broken into 10 byte substrings. The server expects a single string so returns a failure message which the websocket successfully receives.

I looked at the websocket code and couldn't see where this "parsing" into 10 byte strings could be taking place. Could this be happening while buffers are being created in dequeueWrite()?

I suspect this is not a bug and there is likely something I am missing, especially as I am new to iOS development. Any suggestions will be appreciated.

Thanks

Question how to disconnect from AppDelegate

How do I disconnect the websocket from appdelegate when the app goes into background or closes.

In my main view controller I have a Disconnect method that gets called when a button is tapped, so then I call like this:

var rootViewController = self.window!.rootViewController
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Main") as ViewController

        setViewController.DisconnectSocket(self)

And it looks like its trying to disconnect but the server shows the connection still open, and indeed if I go back into the app it still is connected.

Help me please "background mode"

I uses background VoIP

My code:

    func applicationDidEnterBackground(application: UIApplication!) {
        if self.background_task == UIBackgroundTaskInvalid{
            background_task = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
                UIApplication.sharedApplication().endBackgroundTask(self.background_task)
                self.background_task = UIBackgroundTaskInvalid
            })
        }
        UIApplication.sharedApplication().setKeepAliveTimeout((10*60), handler: {
            if self.background_task == UIBackgroundTaskInvalid{
                self.background_task = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
                    UIApplication.sharedApplication().endBackgroundTask(self.background_task)
                    self.background_task = UIBackgroundTaskInvalid
                })
            }
        })
    }

But if my apps is in background > 3 min web socket Disconnected :(

Thanks.

Please upgrade pod install

Hi.
Thanks the swift 1.2 upgrade works fine, but please upgrade the cocoapods installation also because it still install the 0.9.2 version. Thanks. Great work!

Your Install Instructions Don't Work

dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Users/mmain/Library/Developer/Xcode/DerivedData/GoddamnIt-ckykmwrqrfjsapewtbzpncynxuuq/Build/Products/Debug/StarscreamOSX.framework/Versions/A/StarscreamOSX
Reason: image not found

WebSocketDelegate's methods should receive a websocket object as it's first parameter

Something like this:

public protocol WebSocketDelegate: class {
    func webSocketDidConnect(webSocket: WebSocket)
    func webSocket(webSocket: WebSocket, didDisconnect error: NSError?)
    func webSocket(webSocket: WebSocket, didWriteError error: NSError?)
    func webSocket(webSocket: WebSocket, didReceiveMessage text: String)
    func webSocket(webSocket: WebSocket, didReceiveData data: NSData)
}

The delegate object may has no reference to the WebSocket and it may need the webSocket parameter to do it's work. Or in another case, the delegate object is a delegate of multiple WebSockets, the webSocket parameter can be used to distinguish which WebSocket is triggering this event.

Delegate methods not called

I tried a basic setup, and although the socket connection is made (as seen on the server) and the data is able to reach the server (as seen on the server), none of the delegate methods is ever called. We used the following test setup:

//
//  ViewController.swift
//  SocketTest
//
//  Created by Michael Teeuw on 02/09/14.
//  Copyright (c) 2014 Michael Teeuw. All rights reserved.
//

import UIKit

class ViewController: UIViewController, WebsocketDelegate {


    var socket = Websocket(url: NSURL.URLWithString("ws://192.168.178.107:8001"))
    var button =  UIButton.buttonWithType(UIButtonType.System) as UIButton

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        socket.delegate = self
        socket.connect()

        button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitle("Go", forState: UIControlState.Normal)
        view.addSubview(button)

    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        button.frame = view.frame
    }

    func buttonAction(button:UIButton)
    {
        socket.writeString("Test")
    }

}

// MARK - Delegate Methods
extension ViewController {

    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)")
        //self.socket.writeString(text) //example on how to write a string the socket
    }
    func websocketDidReceiveData(data: NSData) {
        println("got some data: \(data.length)")
        //self.socket.writeData(data) //example on how to write binary data to the socket
    }

}

Library not loaded

dyld: Library not loaded: @rpath/Starscream.framework/Starscream
Referenced from: /private/var/mobile/Containers/Bundle/Application/.........
Reason: image not found

support for wss://

I'm not allowed to directly contribute to Open source projects (sigh), but adding support for secure web sockets is as easy as adding a couple of lines to initStreamsWithData():

    _inputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey)
    _outputStream!.setProperty(NSStreamSocketSecurityLevelNegotiatedSSL, forKey: NSStreamSocketSecurityLevelKey)

Feature request

I was looking at this library, and would like to suggest a few changes to the API.

First, I think it makes sense to add an API to let the user to choose which queue to dispatch_async the delegate methods. Right, it dispatches to the main thread. But sometimes, the networking might happen in the background entirely.

If that makes sense, I think the connect() method can be implemented in a way that it detects which queue (thread) it is executed, and by default to use that queue to dispatch delegate execution.

Crashes on Disconnect

I am calling disconnect when the app is backgrounded and it is causing the app to crash.

On line 323 of Websocket.swift

Any idea why?

Starscream capitalization

The second "s" should be capitalized, like: StarScream

Reasoning:

  1. Otherwise, I don't know if it's star-scream or stars-cream.
  2. Also, it's good to follow the standard project naming convention, e.g., CoreLocation

I think you should also update the GitHub project URL to /StarScream instead of the all-lowercase /starscream. This is easy to do and GitHub automatically does a permanent redirect from the previous URL for you.

Crash EXC_BREAKPOINT code = 1 line 378

I noticed a strange bug. Now I have no idea to fix it.

* thread #30: tid = 0xd7890, 0x00000001000caf90 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2351), bufferLen=Swift.Int at 0x0000000100cf56a8, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17052 at WebSocket.swift:378, queue = 'com.apple.root.default-qos', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1000caf90)
  * frame #0: 0x00000001000caf90 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2351), bufferLen=Swift.Int at 0x0000000100cf56a8, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17052 at WebSocket.swift:378
    frame #1: 0x00000001000cb44c WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2351), bufferLen=Swift.Int at 0x0000000100cf5800, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 320 at WebSocket.swift:566
    frame #2: 0x00000001000caf60 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2243), bufferLen=Swift.Int at 0x0000000100cf6cc8, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17004 at WebSocket.swift:555
    frame #3: 0x00000001000cb44c WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2243), bufferLen=Swift.Int at 0x0000000100cf6e20, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 320 at WebSocket.swift:566
    frame #4: 0x00000001000caf60 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2117), bufferLen=Swift.Int at 0x0000000100cf82e8, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17004 at WebSocket.swift:555
    frame #5: 0x00000001000cb44c WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2117), bufferLen=Swift.Int at 0x0000000100cf8440, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 320 at WebSocket.swift:566
    frame #6: 0x00000001000caf60 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2010), bufferLen=Swift.Int at 0x0000000100cf9908, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17004 at WebSocket.swift:555
    frame #7: 0x00000001000cb44c WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e2010), bufferLen=Swift.Int at 0x0000000100cf9a60, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 320 at WebSocket.swift:566
    frame #8: 0x00000001000caf60 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e1edc), bufferLen=Swift.Int at 0x0000000100cfaf28, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 17004 at WebSocket.swift:555
    frame #9: 0x00000001000cb44c WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e1edc), bufferLen=Swift.Int at 0x0000000100cfb080, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 320 at WebSocket.swift:566
    frame #10: 0x00000001000c74d8 WeLikeChat`WeLikeChat.WebSocket.(buffer=(value = Builtin.RawPointer = 0x00000001600e1e10), bufferLen=Swift.Int at 0x0000000100cfc548, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(Swift.UnsafePointer<Swift.UInt8>, bufferLen : Swift.Int) -> () + 2020 at WebSocket.swift:395
    frame #11: 0x00000001000c6034 WeLikeChat`WeLikeChat.WebSocket.(self=0x000000015fe89b20) (WeLikeChat.WebSocket)() -> () + 1088 at WebSocket.swift:318
    frame #12: 0x00000001000c5aec WeLikeChat`WeLikeChat.WebSocket.(self=0x000000015fe89b20) (WeLikeChat.WebSocket)() -> () + 1856 at WebSocket.swift:301
    frame #13: 0x00000001000c4614 WeLikeChat`WeLikeChat.WebSocket.stream (aStream=Some, eventCode=(rawValue = 2), self=0x000000015fe89b20)(Swift.ImplicitlyUnwrappedOptional<ObjectiveC.NSStream>, handleEvent : C.NSStreamEvent) -> () + 784 at WebSocket.swift:247
    frame #14: 0x00000001000c4868 WeLikeChat`@objc WeLikeChat.WebSocket.stream (WeLikeChat.WebSocket)(Swift.ImplicitlyUnwrappedOptional<ObjectiveC.NSStream>, handleEvent : C.NSStreamEvent) -> () + 60 at WebSocket.swift:0
    frame #15: 0x00000001872b6ebc CoreFoundation`_signalEventSync + 192
    frame #16: 0x00000001872c3cc0 CoreFoundation`_cfstream_solo_signalEventSync + 236
    frame #17: 0x00000001872b69d4 CoreFoundation`_CFStreamSignalEvent + 480
    frame #18: 0x0000000186cb2c70 CFNetwork`SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 64
    frame #19: 0x0000000186cb27e8 CFNetwork`SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 216
    frame #20: 0x0000000186cb26cc CFNetwork`SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 88
    frame #21: 0x0000000187319cdc CoreFoundation`__CFSocketPerformV0 + 668
    frame #22: 0x00000001873169ec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #23: 0x0000000187315c90 CoreFoundation`__CFRunLoopDoSources0 + 264
    frame #24: 0x0000000187313d40 CoreFoundation`__CFRunLoopRun + 712
    frame #25: 0x00000001872410a4 CoreFoundation`CFRunLoopRunSpecific + 396
    frame #26: 0x00000001881497a4 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 316
    frame #27: 0x00000001000c4210 WeLikeChat`WeLikeChat.WebSocket.(data=0x000000015fd7f200, port=Swift.Int at 0x0000000100cfefb0, self=0x000000015fe89b20) (WeLikeChat.WebSocket)(ObjectiveC.NSData, Swift.Int) -> () + 11848 at WebSocket.swift:239
    frame #28: 0x00000001000c0cac WeLikeChat`WeLikeChat.WebSocket.(self=0x000000015fe89b20) (WeLikeChat.WebSocket)() -> () + 8952 at WebSocket.swift:182
    frame #29: 0x00000001000cf098 WeLikeChat`WeLikeChat.WebSocket.(self=0x000000015fe89b20) -> () -> ()).(closure #1) + 64 at WebSocket.swift:133
    frame #30: 0x00000001000cf0d0 WeLikeChat`reabstraction thunk helper from @callee_owned () -> (@unowned ()) to @callee_unowned @objc_block () -> (@unowned ()) + 36 at WebSocket.swift:132
    frame #31: 0x0000000100a78e30 libdispatch.dylib`_dispatch_call_block_and_release + 24
    frame #32: 0x0000000100a78df0 libdispatch.dylib`_dispatch_client_callout + 16
    frame #33: 0x0000000100a859a0 libdispatch.dylib`_dispatch_root_queue_drain + 1280
    frame #34: 0x0000000100a86f18 libdispatch.dylib`_dispatch_worker_thread3 + 132
    frame #35: 0x00000001982c92e4 libsystem_pthread.dylib`_pthread_wqthread + 816

Send data in background mode?

If my apps in background mode what not send data to socket.

Code:
socket = WebSocket(url: NSURL(scheme: "ws", host: host, path: "/")!)
socket.delegate = self
socket.voipEnabled = true
socket.connect()
...............
...............
dispatch_async(dispatch_get_main_queue(),{
self.timer = NSTimer.scheduledTimerWithTimeInterval( 60.0 , target: self, selector: Selector("sendPaketBG"), userInfo: nil, repeats: true)
})
...............

func sendPaketBG(){
self.socket.writeData(myData)
}

Thanks.

Crash EXC_BREAKPOINT code = EXC_I386BPT

I had the issue with

inputStream!.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream!.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
inputStream!.close()
outputStream!.close()

when I try to reconnect the websocket when I lose the connection to the server.
I could solve it

inputStream?.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream?.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
inputStream?.close()
outputStream?.close()

but this code does not solve the problem 100% of the time

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.