Today I try the QOTD-NIO-Final project (download via https://koenig-media.raywenderlich.com/uploads/2018/03/QOTD-NIO-3.zip ), but it’s not working.
Mobile app does not get the quote. In refreshQuote method, there has response, but message is empty, string is empty.
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!
Sure enough, that’s the issue.
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:
.package(url: "https://github.com/apple/swift-nio.git", .exact("1.1.0"))
I will update the materials as soon as possible.
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.
How can i get the client IPv4 address from a bluesocket connection on the channelActive function ?
@dokun1 Can you please help with this when you get a chance? Thank you - much appreciated! :]
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!
This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!