Mobile developers often work with REST APIs or other networking protocols in their applications to access data or to coordinate activities. In this tutorial you will create a Swift Server with SwiftNIO, a low-level networking framework that makes creating TCP servers easier than before.
Yes, the server is running. When I tap the refresh button in the app’s navigation bar, no quote shows in the app. And I’m sure the app is running into refreshQuote method, but the message is empty.
I ran into the same issue. I found that it worked if I modified the “QuoteHandler” in the server code to use the function “channelActive(ctx: ChannelHandlerContext)” instead of “channelRegistered(ctx: ChannelHandlerContext)”. If you read the documentation on SwiftNIO, you shouldn’t try to read/write to the socket until its active and so there was probably a timing issue taking place.
Sorry for the delayed reply here - it looks like @psychoticidiot nailed the issue, but I am wondering if this is because of a version bump. I pulled the materials and it no longer works for me either, but NIO is now on v1.4.2, so something must have changed. However, conceptually @psychoticidiot is right due to the way these sockets should be read.
I apologize for the inconvenience - I’ll work on an update as soon as I’m able to!
For those reading this tutorial, until the materials are updated, please change the line in Package.swift where the NIO dependency is declared to this for the time being:
The materials have been updated. I’ll edit the tutorial later to get the socket connection right, but v1.1.0 of NIO is pinned in the SPM manifest now, so everything works as it should.
Hi there @ffabri! If you put a breakpoint somewhere inside channelActive and send a request, try printing out ctx.remoteAddress and this should print out your address whether you configure everything for IPv4 or IPv6. Let me know if this answers your question!