我有一个 phoenix liveview 应用程序来尝试 Liveview 本机,我想从我的 iPad 连接到它。 我在linux上,所以允许使用ufw访问端口4000,但在我的ipad上连接仍然失败(我使用lvn go应用程序)。
我尝试连接时在 lvn go 中遇到的错误:
initialFetchError(Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={_kCFStreamErrorCodeK
ey=61, NSUnderlyingError=0x30177dbf0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), viable, interface: en0[802.11], ipv4, ipv6, dns, uses wifi, _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <04A35415-75B1-4226-9096-BFB3FE59C8E7>.<9>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <04A35415-75B1-4226-9096-BFB3FE59C8E7>.<9>"
), NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=http://192.168.1.140:4000/?_interface%5Btarget%5D=ipados&_interface%5Bbundle_id%5D=com.dockyard.LiveViewNativeGo&_interface%5Bapp_version%5D=0.3.1&_interface%5Bos%5D=iOS&_interface%5Bi18n%5D%5Btime_zone%5D=Europe/Paris&_interface%5Bos_version%5D=17.7.1&_interface%5Bapp_build%5D=1&_interface%5Bl10n%5D%5Blocale%5D=en_FR&_format=swiftui, NSErrorFailingURLKey=http://192.168.1.140:4000/?_interface%5Btarget%5D=ipados&_interface%5Bbundle_id%5D=com.dockyard.LiveViewNativeGo&_interface%5Bapp_version%5D=0.3.1&_interface%5Bos%5D=iOS&_interface%5Bi18n%5D%5Btime_zone%5D=Europe/Paris&_interface%5Bos_version%5D=17.7.1&_interface%5Bapp_build%5D=1&_interface%5Bl10n%5D%5Blocale%5D=en_FR&_format=swiftui, _kCFStreamErrorDomainKey=1})
如果没有更多信息,很难说,但需要检查的一件事是由
config/dev.exs
生成的 mix phx.new
的这一部分:
config :my_app, MyAppWeb.Endpoint,
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: 4000],
对我来说,将最后一行更改为:
http: [ip: {0, 0, 0, 0}, port: 4000],