daltoniam / starscream Goto Github PK
View Code? Open in Web Editor NEWWebsockets in swift for iOS and OSX
License: Apache License 2.0
Websockets in swift for iOS and OSX
License: Apache License 2.0
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
"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.
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.
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.
Hello,
It is possible to automatically reconnect if the socket is disconnected ?
thk's
Is it cruft, i.e., an unnecessary file that can be deleted?
Since it's spelled WebSocket, shouldn't it always be written as either WebSocket...
or webSocket...
in Swift code?
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:
I know you can't support every dev tool out there, but I think these two changes have some other beneficial effects too.
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.
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
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?
dyld: Library not loaded: @rpath/Starscream.framework/Starscream
Referenced from: /private/var/mobile/Containers/Bundle/Application/.........
Reason: image not found
Support swift 1.2
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.
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
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*/
}
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))
}
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.
}
}
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
}
}
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.
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'
As discussed here : 6273bb5#commitcomment-7999709
WebSockets should support sending data on channels, no?
First of all, good work!
WAMP v2 seems to be supported, but is there also the possibility to use this with WAMP v1? Thank you! :)
Could you integrate Cocoapod please?
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.
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
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?
.
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()?
how work background mode?
Great work Dalton.
Perhaps add a demo app.
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 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.
Sometimes a certain timeout for connection attempts is needed. Having a function to set the timeout of websocket be a good functionality.
Hi,
I'm getting about 15 errors in the new XCode.
Are you planning to support it ?
Thanks,
Shai
Hi,
this looks great, however I'm trying to connect to a node js server running socket.io.
Has anyone been successful doing this?
I think there maybe an issue with the handshake http://www.teehanlax.com/blog/how-to-socket-io-swift/ talks about it here, I've tried to used socketRocket also, but haven't had any luck.
Thanks,
Wesley
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 WebSocket
s, the webSocket
parameter can be used to distinguish which WebSocket
is triggering this event.
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
Starscream cannot process messages larger than 65536 characters.
Steps to reproduce:
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'));
});
Connect to server using Starscream
Crash should be triggered:
EXC_BAD_ACCESS (code=EXC_ARM_DA_ALIGN, address={{ *address removed* }} )
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)
When I have the ruby ws-server running and try to use the sample app, I get the error "websocket is disconnected: The operation couldn’t be completed. Connection refused".
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?
The second "s" should be capitalized, like: StarScream
Reasoning:
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.
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?
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!
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.