WebSockets

Does anyone have a working implementation of making a WebSocket connection in iOS or with Xojo.Net.HTTPSocket they are willing to share before I embark on writing my own?

Thanks,

Maybe not exactly what you’re looking for, but my recent adventure with HTTPSocket on iOS is documented here:

https://forum.xojo.com/49532-httpsocket-post-multipart

Kem has a WebSocket implementation on his github account. Maybe you should fork that and go from there.

https://forum.xojo.com/32077-websocket-open-source-project

Yeah I’ve seen Kem’s class. It’s pretty good but it’s based on the classic SSLSocket (so no iOS) and therefore also cannot implement HTTP 1.1. This leads to some weird edge bugs.

I’m cracking on with my own implementation.

[quote=407978:@Garry Pettet]Yeah I’ve seen Kem’s class. It’s pretty good but it’s based on the classic SSLSocket (so no iOS) and therefore also cannot implement HTTP 1.1. This leads to some weird edge bugs.

I’m cracking on with my own implementation.[/quote]
Ah, I thought Kem had an option to use Xojo.Net.TCPSocket on the client side.

Sadly not (at least not that I can see).

How come Xojo.Net.HTTPSocket can’t connect to ws or wss URLs? I understand that I need to specify different headers, negotiate the handshake etc but why does it just point blank refuse to connect? The old SSLSocket connected to ws and wss (which is what Kem does - he hasn’t written his own TCP backend).

Is this something that would be very hard for Xojo to add?

Garry, is there any reason to not implement Kem’s code by adapting it to Xojo.Net.TCPSocket ?
Xojo.Net.HTTPSocket won’t connect to ws URLs, but I’m sure .TCPSocket will

Garry, you’ve got two threads going about this topic, one for iOS and one for desktop. Which of these are you actually trying to solve?

I’m trying to implement a cross platform (including iOS) WebSocket client. I’m happy to keep the discussion going in this thread for ease of reference.

[quote=408011:@Jeremie Leroy]Garry, is there any reason to not implement Kem’s code by adapting it to Xojo.Net.TCPSocket ?
Xojo.Net.HTTPSocket won’t connect to ws URLs, but I’m sure .TCPSocket will[/quote]
Xojo.Net.TCPSocket isn’t available on desktop.

The setup I have is a desktop app based on @Tim Dietrich Aloe Express. This accepts WebSocket connections from clients. I have a Javascript client interacting with the Aloe Express server flawlessly.

The problem I’m seeing on the desktop with @Kem Tekinay WebSocket class is that if the Aloe Express server sends multiple JSON WebSocket messages in quick succession, @Kem Tekinay class throws an error when decoding saying that the data is not UTF-8 encoded. There seems to be bug in Kem’s code in that it is using the SSLSocket's DataAvailable() event and reading all available data but this is leading to incorrect concatenation of two JSON messages with the Unicode replacement character.

The reason I wanted to rewrite using a more modern class was that I thought it might be to do with HTTP 1.1 vs HTTP 1.0. I am sure the bug is in the WebSocket class as my server app works perfectly with Javascript, Ruby and Python. It’s only the Xojo client that has this bug.

If the server sends the WebSocket messages slowly then the bug doesn’t surface.

I believe that is a bug that @Greg O’Lone fixed in a branch I have to integrate. He was hurricane-delayed so I’m not sure when that will happen, but I hope soon.

Amazing! That sure would beat me trying to wrap my head around rewriting the class!

I hope you’re OK Greg.

I can confirm that Greg’s latest commit to his M_WebSocket fork works perfectly. Great work both of you.

That and working long hours on a release :stuck_out_tongue: