Swift Websocket Server Example using Vapor 4.0

This project includes a minimum working example for a websocket server written in Swift. To interact with it I recommend using websocat (Github-Link).

Part of the challenge was to binary-encode and decode JSON payload into predefined Swift structs which are stored in the Sources/App/websocket/messages folder.

How to use

  1. Build and run using swift build and swift run
  2. In this example the websocket is served under the /channel path. In the terminal connect to the websocket server using websocat:

    # '-b' transfers payload binary encoded
    websocat -b ws://
  3. Paste into the console the JSON payload in the valid format (it is of type WebsocketMessage<Connect>):
  4. The websocket server should return the following message which should be displayed in the terminal decoded as string:


View Github