phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.4k stars 2.87k forks source link

Nothing happens when joining from iOS #2018

Closed dmdque closed 7 years ago

dmdque commented 7 years ago

Environment

Expected behavior

Join room from iOS and see logs on the server to confirm that the room has been joined.

Actual behavior

Join room from iOS, no logs on server.

Description

I'm using a simple Phoenix instance, and have a simple channel join event working as expected with a JS client. I'm using the following on iOS SwiftPhoenixClient:

let socket = Socket(domainAndPort: "localhost:4000", path: "socket", transport: "websocket")
socket.join(topic: "room:lobby", message: Message(subject: "status", body: "joining")) { channel in
    let channel = channel as! Channel
    print("join")
}

But nothing is logged on the server. I also tried with Birdsong with the same result:

    let socket = Birdsong.Socket(url: URL(string: "http://10.88.111.2:4000/socket/websocket")!)
    socket.connect()

I'm watching the traffic going through the server's port 4000 (sudo tcpdump port 4000) and am seeing some packets flow every time I trigger the above code. eg. (10.88.111.2 is the server's IP, and 10.88.111.30 is the iOS client's IP)

// With SwiftPhoenixClient
14:21:48.161241 IP 10.88.111.30.61762 > 10.88.111.2.terabase: Flags [S], seq 110794316, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 861181191 ecr 0,sackOK,eol], length 0
14:21:48.161393 IP 10.88.111.2.terabase > 10.88.111.30.61762: Flags [S.], seq 1986623172, ack 110794317, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 607536416 ecr 861181191,sackOK,eol], length 0
14:21:48.163864 IP 10.88.111.30.61762 > 10.88.111.2.terabase: Flags [R], seq 110794317, win 0, length 0

// With Birdsong
14:21:51.362180 IP 10.88.111.30.61763 > 10.88.111.2.terabase: Flags [S], seq 1908544453, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 861184367 ecr 0,sackOK,eol], length 0
14:21:51.362332 IP 10.88.111.2.terabase > 10.88.111.30.61763: Flags [S.], seq 31220766, ack 1908544454, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 607539593 ecr 861184367,sackOK,eol], length 0
14:21:51.365562 IP 10.88.111.30.61763 > 10.88.111.2.terabase: Flags [R], seq 1908544454, win 0, length 0

I've also created a ticket here: https://github.com/davidstump/SwiftPhoenixClient/issues/61. But it seems unlikely that the client is the issue since this happens with two of them.

josevalim commented 7 years ago

Does it work through regular JS websocket?

dmdque commented 7 years ago

Yes it does. Joining channels and chatting works fine with https://github.com/chrismccord/phoenix_chat_example. But using the same backend with an iOS client doesn't.

chrismccord commented 7 years ago

Do you have check_origin: false in your endpoint config? By default we check origin which makes sense for browsers, but not other clients. Can you confirm it's disabled?

chrismccord commented 7 years ago

Though I would expect our logs to whine at you about this, but lets start there

dmdque commented 7 years ago

Yup, I've got that line.

chrismccord commented 7 years ago

Does the birdsong client log anything? Is the connection established on the client?

dmdque commented 7 years ago

Hold on, I got the Birdsong client to work. Looks like I was missing some code to make it actually join:

let socket = Birdsong.Socket(url: URL(string: "http://10.88.111.2:4000/socket/websocket")!)
socket.onConnect = {
    let channel = socket.channel("room:lobby", payload: ["user": "test"])
}
socket.connect()

In an effort to keep things simple I left out onConnect, thinking that it did nothing important. Too much simplification...

SwiftPhoenixClient still isn't working though, but it's not an issue with this project.

Thanks!