swift-nio: Could not connect to local server from iOS simulator

Expected behavior

app run on iOS simulator could connect local server on host successful

Actual behavior

app run on iOS simulator could not connect local server on host. but localhost server is connected by cURL properly

Steps to reproduce

  1. Run server on host ( use Netty )
  2. Run iOS App on simulator.
  3. Connect to local server from simulator.

If possible, minimal yet complete reproducer code (or URL to code)

import Foundation import NIO

enum TCPClientError: Error { case invalidHost case invalidPort }

class TCPClient { private let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) private var host: String? private var port: Int?

init(host: String, port: Int) {
    self.host = host
    self.port = port
}

func start() throws {
    guard let host = host else {
        throw TCPClientError.invalidHost
    }
    guard let port = port else {
        throw TCPClientError.invalidPort
    }
    do {
        let channel = try bootstrap.connect(host: host, port: port).wait()
        try channel.closeFuture.wait()
    } catch let error {
        throw error
    }
}

func stop() {
    do {
        try group.syncShutdownGracefully()
    } catch let error {
        print("Error shutting down \(error.localizedDescription)")
        exit(0)
    }
    print("Client connection closed")
}

private var bootstrap: ClientBootstrap {
    return ClientBootstrap(group: group)
        .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
        .channelInitializer { channel in
            channel.pipeline.addHandler(TCPClientHandler())
    }
    
}

}

[anything to help us reproducing the issue] Console output log :

2020-09-01 05:05:31.562214+0700 iDine[15933:709466] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke Error: The operation couldn’t be completed. (NIO.ChannelError error 0.) Client connection closed

SwiftNIO version/commit hash

SwiftNIO 2.20.2

Swift & OS version (output of swift --version && uname -a)

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7) Target: x86_64-apple-darwin19.3.0 Darwin Macs-MacBook-Air.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 30 (15 by maintainers)

Most upvoted comments

Dear @weissi,

Thank you for your very details information with your patient.

Actually I have just checked again, and found that it did not any issues with the connection between client( inside iOS Simulator ) and server ( host machine ), and the issue related to Protobuf decoder and encoder.

Now I could receive message normally.

@Davidde94, @weissi :

Thanks for your feedbacks.

Let me check again then let you know the result

Instead of using a Netty server, can you use netcat? Try starting a netcat server with nc -l 127.0.0.1 9090 and then making the connection from the simulator.