An Introduction to WebSockets | raywenderlich.com

Learn about WebSockets using Swift and Vapor by building a question and answer client and server app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/13209594-an-introduction-to-websockets

I have always been happy with raywenderlich.com articles. They are generally VERY good quality. I have learnt much from them and I am grateful they are there.

However, I am not very happy with this article. Having never used websockets before I wanted to learn about them and came here. The article is easy to understand and that’s great. Except I can’t get the example to run! Even if I download the resources and run the final product, no dice.

I have tried Xcode 11 (as specified), Xcode 12. I even tried upgrading the libraries. No luck. I can get the basic connection handshake working but cannot send messages and I have no idea why.

This is particularly frustrating as my experience with this website has up to now been excellent. If someone could check out the code and perhaps reproduce the problem that would be great.

I have no idea why its not working and normally I don’t have to debug your guys code. Usually its my code that’s buggy! Any help would be appreciated!

Hi @rleclus,

That’s very unfortunate to hear! Do you have any extra information to offer? What exactly is not working? Everything, or just a specific part. And is it the backend part, or the iOS app that’s misbehaving.

If you can provide some extra details I’m more than happy to look into it, so we can get your project working again :smiley:

Thanks!

I had the same issue as well.

The error messages are as follows:
The package product ‘SQLiteNIO’ requires minimum platform version 13.0 for the iOS platform, but this target supports 8.0.

The package product ‘Crypto’ requires minimum platform version 13.0 for the iOS platform, but this target supports 8.0.

Hi there, thanks a lot for this tutorial. Everything worked fine for me except the last part with ‘Answering the Questions’ where we build in the Leaf page. After inserting the first code snipped the html page doesn’t display anything except a json string. In the console I am getting this error everytime refreshing the page:

[ ERROR ] LeafError(file:"/Users/*/Library/Developer/Xcode/DerivedData/websockets-backend-…/SourcePackages/checkouts/leaf-kit/Sources/LeafKit/LeafSource/LeafSources.swift", function: “searchSources(t:on:s:)”, line: 76, column: 69, reason: LeafKit.LeafError.Reason.noTemplateExists(“questions”))

At the error line there is this following code: guard !s.isEmpty else { return eL.makeFailedFuture(LeafError(.noTemplateExists(t))) }

I was only interested in the socket stuff so I am really happy that it worked so far, but maybe other people want to get Leaf to work as well, would be really helpful for them to fix that part I guess :slightly_smiling_face:
Thanks so much,
Chrissi

Hi,
Thank you for the project, it’s really great.
In the example, the server side listen to the port 8080 and I have to use an other one.
So I would like to know if it’s possible to change the listening “port”.

Thank you.

As a person who has designed a lot of tech education curriculum, I have to ask you, what are you actually trying to teach here?

The information that anybody would come to this page to learn is not “how do I create a Q&A system?” If they did, the title would represent that. I came here, and I’m sure that 99% of others came here to learn how to use Websockets. Is that in this tutorial? Yes, it is.

Now the question is, what level of understanding would a visitor need to bring to this page to extricate that information from the endless cruft? And the answer is, More than is needed to follow the tutorial.

If you’re going to teach someone a skill, start with the skill. Then, elaborate on it. If you want, before you teach them the core skill, talk about the applications that this technique has. What if I’m trying to keep two players’ iOS games in sync? What if I’m trying to push out an up-to-the-minute information system for whose car is up for service in a garage? What if I’m trying to gather the readings of 500 sensors in an IoT network, and send those on to a series of warning devices?

The reality is that about 90% of what’s in this project would need to be stripped out to make this relevant to those use-cases.

If you don’t know what an MVP is, research it, and think about it. But I’m sure you do. This should start as an MVP, and then take it in other directions, if that’s appropriate.

In programmer talk, this is separation of concerns. You do it every day, when you code professionally. Why not here? Separate the actual subject (the Controller), from the implementation (the Presentation layer), and the specific type of data (the Model). Establish the Controller, mock in the data, assume the interface will be handled by others who don’t need to know how the sausages are made. Simple.

Some Wenderlich material is good. This is not.

Wanted to learn more about WebSockets, didn’t even get out of “Testing the WebSocket” chapter, because provided web service doesn’t work anymore. Please update material.

1 Like

Same here. Decided to give this a try as a learning exercise/to up skill a bit, and the web service is not available, - but worse, the project doesn’t even build because some of the dependencies are out of date. I really hope there’s an updated version out or at least in the works.

Hi! I’m having issues while running the backend project, the error says:

  • ‘Float80’ is unavailable: Float80 is not available on target platform

I’m using a Macbook air M1.

I had that problem, make sure you’re compiling with Rosetta
Screen Shot 2022-02-23 at 10.18.25 AM

Seems to now work, I’m able to go through all the tutorial with no issues. For the websocket server I used websocket king client extension in chrome. I’m pretty sure piesocket extension can also work.