Group Group Group Group Group Group Group Group Group
raywenderlich.com Forums

WebSockets on iOS with Starscream

Learn how to use Starscream to add always-on networking with WebSockets in this iOS tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/861-websockets-on-ios-with-starscream

This is an interesting tutorial. I have one problem though. I was able to run the app on simulator and send messages between the simulator and Safari without any problem. When i install the app on my iPhone 7 Plus, i can’t get past the username screen. Each time i press the next button, the websocketDidDisconnect gets called and i go back to the username selection screen. I get this message at the Xcode console: __nw_connection_get_connected_socket_block_invoke 1 Connection has no connected handler
Do you know how i can fix this?
Thanks.

EDIT: I even tried the demo project of StarScream from their Github page and i have the same problem.

You’ll have to find out what the IP address of your computer is and update the app to connect to that instead of localhost.

1 Like

Now it works perfectly! Thanks Aaron!

I’m getting an error “Optional(Error Domain=WebSocket Code=200 “Invalid HTTP upgrade” UserInfo={NSLocalizedDescription=Invalid HTTP upgrade})” - what is causing this?

1 Like

Hello,
I trying to create Chat Server Socket with Java language. I created simple server using Mina apache (https://mina.apache.org/mina-project/userguide/ch2-basics/sample-tcp-server.html) but Client can not connect to this chat server. Can you give me a simple server code in Java ?

Thanks for your help.
Vu

Hello,

I am attempting to access stream data using Starscream web sockets, which is working on traditional calls, but not on the below as I need to have the --user USERNAME:TOKEN

curl --user USERNAME:TOKEN https://streamingxxxxxxx.com/stream/KEY/?values=value1,valu2,value3,value4

This works just fine in a Terminal window (Mac OS X), but my question is how would I handle the authorization --user USERNAME:TOKEN in a WebSocket call. I have tried in the socket header but that did not work. I have also tried wss:// which did not work.

I am using Swift 3.0.

Thank you

got same problems. how to fix it?

@vupv4 & @gbacklin There’s some weird thing with Apple’s networking implementation that came up in a Starscream issue on GitHub. Try using 127.0.0.1 or the IP address of your machine instead of localhost.

If that works, please let me know and I’ll update the tutorial.

This worked in browser first time but after 3 messages it thrown some error and when I tried restarted the server I see this error.

events.js:182
throw er; // Unhandled ‘error’ event
^

Error: listen EADDRINUSE :::1337
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at Server.setupListenHandle [as _listen2] (net.js:1305:14)
at listenInCluster (net.js:1353:12)
at Server.listen (net.js:1453:7)
at Object. (/Users/Harariya/Documents/Chat_Sample/EmojiTransmitter/nodeapp/chat-server.js:41:8)
at Module._compile (module.js:569:30)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)

I am not sure what went wrong or what did I miss.

Thanks for your great tutorial.

As a new developer of iOS, can I ask you one question? How could I use the example to build an app with location sharing? Or is there any other example for reference?

Thanks again.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]