套接字无法连接到端点 [英] Socket won't connect to Endpoint
问题描述
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
端点上有套接字,对吧?
But I do have the socket on the /ws
endpoint, right?
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
它应该能够连接到该端点,但是由于某种原因它根本无法到达该端点.
It should be able to connect to that endpoint, but for some reason it can't reach it at all.
[info] Running Sapphire.Endpoint with Cowboy on http://localhost:4000
推荐答案
@JoséValim找到了解决方案.
@JoséValim found the solution.
我将phoenix.js库移植到coffeescript,却错过了路径的后缀应该是传输层所在的事实.在这种情况下,在实现的最后需要/websocket
. :)
I was porting the phoenix.js library to coffeescript and missed the fact that the suffix of the path should be whatever the transport layer is. In this case, it needed /websocket
at the end in the implementation. :)
这篇关于套接字无法连接到端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!