Open ladybugkiller opened 8 years ago
Hi, sorry for the late response. I just tried and I ran into an error on the phoenix chat example server about having to change the host. This might be the problem you had as well. Check config.exs in the phoenix chat example and change the host from localhost
to whatever the ip address is that the server is on. Restart the server and then see if that helps.
Thanks for the reply!
I tried making the changes that you suggested, but still run into the same problem. It appears that the app is unable to receive/send messages. The server itself though, seems to run without any problems so far.
I believe there's something wrong with channnel.join().receive functions. Somehow none of those functions get executed.
The "WebSocket connection error java.net.ProtocolException: Expected HTTP 101 response but was '200 OK'" that I posted about earlier happens every time I get a ping from the server. So instead of seeing it as an incoming "ping" message on the app, I get it as a error message in my console.
Do you have any idea what could possibly be causing this problem and how I should go about fixing it?
Thanks for your time!
have you fix this?
@af913337456 Have you looked into any solutions for this? I've got a partial on a potential fix though I am not 100% sure if it solves the problem. I am not sure if Phoenix is supposed to implement the get request to upgrade from an HTTP/S protocol to the WS protocol but here is a plug I made that you can add to your endpoint to at least solve the 101 instead of 200 error. It still fails on reserved flags are unsupported but it does flash that it is connected for a second. So maybe this just needs to be tweaked a little bit to fix this?
scope "/socket" do
pipe_through :websocket
get "/", PagesController.index # route somewhere....
end
pipeline :websocket do
plug :change_protocol
end
def change_protocol(%{req_headers: headers} = conn, _) do
# see https://tools.ietf.org/html/rfc6455 for info on how to implement the response to a 101 request
key = Map.new(headers)["sec-websocket-key"]
resp_token = key <> "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
encoded_token = :crypto.hash(:sha, resp_token) |> Base.encode64
conn
|> put_resp_header("Upgrade", "websocket")
|> put_resp_header("Connection", "Upgrade")
|> put_resp_header("Sec-Websocket-Accept", encoded_token)
|> send_resp(101, "Switching Protocol")
|> halt
end
NM, the solution is that you are not pointing to the correct location. You set up your socket at /socket
but you also set up your transport called websocket
. The full path to your socket is /socket/websocket
NOT /socket
.
try with this ,
my problem fixed with this !
Hi sorry to bother you, I'm trying to run your AnroidPhoenixDemo, but I run into this error: WebSocket connection error java.net.ProtocolException: Expected HTTP 101 response but was '200 OK' at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:144) at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:43) at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:117) at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:170) at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574) at java.lang.Thread.run(Thread.java:1020)
For the buildConfig host variable, I did as you instructed and used "ws://myipaddress:4000". The server itself is running fine on my machine, but the chat app on Android can't send out or receive messages. Do you have any idea how should I go about this? Thanks!