I've downloaded NIOWebSocketClient and NIOWebSocketServer and copied each into Swift Packages on a Pi running 64bit BullsEye. They compile and run together perfectly on the same machine when using the default run arguments, but not when given a hostname and port. For example...
(Paintext) HTTP runs over port 80 by default and WebSocket is usually upgraded from HTTP(S). So if you have a public server that speaks plaintext WebSocket (ws://...) then you can just put port 80 there. I will say that today, server (hopefully) don't speak plaintext HTTP anymore. They speak HTTPS and upgrade WebSocket from there (wss://..., note the extra s).
NIOWebSocketClient however is just a demo how to use NIO's WebSocket handlers. If you want to speak WebSocket over TLS (wss://...) as you should, then you'd need to combine that with a TLS implementation such as swift-nio-ssl or swift-nio-transport-services (which on Apple platforms lets Network.framework to the networking & TLS).
I will say that if you just want to use WebSocket, then NIO* is the wrong tool, it's way too low-level for what you're trying to do. I would recommend Vapor's websocket-kit if you want to use a WebSocket. It will do all the NIO & TLS bits for you.
Of course, if you're looking into NIOWebSocket for educational reasons or you want to create your own WebSocket library, then go ahead .
I'm going around in circles with NIO, so I'd like to try using web socket-kit as you suggest, but the README file has no content. Please tell me where It can see some practical examples of how to use it.
I'm almost a year into developing a Swift / SwiftNIO / SwiftUI system using an iMac and 2 remote 64bit Debian RPi Servers to control and monitor a Digital Amateur TeleVision transmitter, receiver, power supplies and cooling, which will communicate with the wide band transponder on a geostationary satellite.
This is not your average 99 cent IOS App. I've spent thousands of my money on this project and its almost ready to share with the community, but the networking side has been a pain since day two - when I migrated from Python to Swift.
I'm pleased to hear your intent to add examples, but please can you give me some idea on how much longer I'll be left in the dark?
To @johannesweiss and @0xTim
FYI I've installed Vapor on a spare RPi and I can confirm that it works on Debian Bullseye 64bit Lite and Swift 5.6. I even managed to get TLS working even though the documented method didn't work for me. Maybe this is the way I should go, so I'll play with this for a while and pester you later.
My app requires a continuous 'stream' of json status data - without being asked by a request. But, it will need to act on a number of specific requests.
Searching the Internet for help is futile, because its swamped with outdated IOS articles. Not many seem to be interested in real time machine control.