var socket = new Socket("localhost:4000")
socket.connect()
返回WebSocket connection to 'ws://localhost:4000/ws' failed: Error during WebSocket handshake: Unexpected response code: 404
插座将无法连接到端点
但我确实对/ws
端点插座,对不对?
defmodule Sapphire.Endpoint do
use Phoenix.Endpoint, otp_app: :sapphire
socket "/ws", Sapphire.MomentSocket
plug Plug.Static,
at: "/", from: :sapphire, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
end
plug Plug.RequestId
plug Plug.Logger
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session,
store: :cookie,
key: "_sapphire_key",
signing_salt: "hW1bFEcR"
plug Sapphire.Router
end
它应该能够连接到该端点,但由于某种原因,它根本无法达到它。
[info] Running Sapphire.Endpoint with Cowboy on http://localhost:4000
由于您正在访问'ws:// localhost:4000/ws',我有一个预感,您正在使用旧凤凰客户端与最近的凤凰应用程序。确保你使用的是Phoenix 1.0.2,并且你拥有Phoenix.js的最新版本。 –
@JoséValim嗯,我已经将https://github.com/phoenixframework/phoenix/blob/master/web/static/js/phoenix.js移植到前端服务于其他服务器的coffeescript中。客户端自动添加'/ ws',所以我有'socket'/ ws“,Sapphire.MomentSocket'应该在'/ ws'路径中不可用?即使将两者都更改为'/ socket'也会返回相同的404。我对该套接字端点如何暴露感兴趣 – iColor
URL是socket_path + transport_name。所以它应该是/ socket/websockets或类似的东西。 –