Terence,
Am 22.05.2014 03:47, schrieb Terence Chow:
> Hi All,
>
> I am a nooby trying to learn so forgive me when I come off as confused.
> I'm trying to make an android chat application where people can have
> many 1 on 1 conversations.
>
> Reading online it seemed like websockets was ideal for chats so I found
> autobahn websockets and started going to work.
Yep, WebSocket is a great fit for chat. In particular, since you can
support native, hybrid and web apps - with 1 protocol.
So I'd say: go with WebSocket. If you end up using Autobahn and/or WAMP,
even better;)
>
> When I built the application, the realtime aspect worked great, but I
> realized that my application was echoing messages either to everyone, or
> only the specific client that opened the connection. I couldn't figure
The client side (Android) is 1 part of such an app. The other part is
the server side.
WebSocket "as is" is just a low-level messaging protocol. It does not
know about "users" or "conversations".
> out how to add details of who connected in the connect method of the
> WebSocketConnection. Due to this, I couldn't track which client was
> which on my server and couldn't send messages to specific individuals.
>
> I'll pause here to check my understanding. Is what I just said correct?
> With the autobahn websocket implementation, there is no way to send
> messages to specific individuals?
Yes. This isn't specific to Autobahn, but just the characteristic of
WebSocket (RFC6455). It is just low-level messaging. It has no notion of
routing messages between multiple clients.
Now, long time ago we figured that apps using WebSocket would often need
"higher-level" services on top of raw WebSocket. And that was the
original itch to scratch with WAMP:
http://wamp.ws/
WAMP was one of the first officially registered WebSocket subprotocols
http://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name
we've been gaining quite some practical experience with the (totally
simple) WAMP v1 spec in real-world app, and last year revised based on
that experience for WAMP v2.
>
> Assuming I'm not missing anything, I then turned to reading about WAMP.
Yes, you are on the right track;)
> Here I kinda saw what I needed to do:
>
> 1) Have each client subscribe to all the chats they are involved in.
> 2) When they need to send a message use a RPC or the method sendTextMessage
>
> Again I'll pause here to check my understanding. What I outlined above
> is the correct way to implement a chat application where you can have
> many 1 on 1 conversations?
There are multiple ways of implementing 1:1 conversations, and as often
in tech., the "correct" approach depends on your specific requirements
and other factors.
I try to outline some variants using PubSub only (there would be more
using RPC):
1)
When a 1:1 conversation is established, make up a _dedicated_
(ephemeral) PubSub topic for that single conversation and just use
PubSub over that topic. Only the 2 participants subscribe and publish to
the dedicated topic.
2)
Use a topic-per-user scheme, where each user subscribes to his personal
"in-box" (timeline) topic, and a 1:1 conversations works by each of the
participants publishing to the in-box topic of the other.
3)
Use a global chat topic to which all users subscribe. Then, for a 1:1
chat, restrict the eligible receivers to the other participant when
publishing. This makes use of another WAMP PubSub feature: you can
publish to a topic, but further restrict the receiver (beyond those
merely subscribed) by providing exclude/eligible WAMP sessions.
>
> The next thing I naturally have to ask is, how will this work on a ruby
> websocket server? I believe I don't need to implement the RPC because I
For WAMP v1, there is a WAMP Ruby implementation:
https://github.com/bradylove/wamp-ruby
http://wamp.ws/implementations/wamp1/
Caveats:
- I haven't used it, so I cannot speak about quality / compatibility
- it uses Faye as underyling WebSocket implementation
- it is for WAMP v1, which is nowerdays deprecated (WAMP v2 is a major
step forward)
That being said: while AutobahnPython/JS/Cpp are all on WAMP v2 already,
AutobahnAndroid is not yet v2.
> can simply use sendTextMessage and manage the messages that way. (Is
> that correct?) Assuming that is correct, then the only thing I need to
> implement is subscriptions and publishing. How do I implement
> subscriptions? I saw the method registerforpubsub in the
> wamptestserver.py but I could not find where that method is actually
> defined so I can't see exactly what it is doing. What would I need to do
> to set up a subscribe / publish wamp server in ruby? Note I'm using
> EventMachine Websockets on the backend...
For WAMP v1, I'd try the above Ruby implementation. Since
AutobahnAndroid is also still on WAMP v1, that might just work.
For WAMP v2, I guess we would need to implement the spec in Ruby:
http://wamp.ws/spec/
https://github.com/tavendo/WAMP/blob/master/spec/basic.md
A complete, interoperable WAMP v2 Ruby implementation would definitely
be welcome! Now, doing this is probably not trivial .. some work .. and
depending on your priorities/background .. don't know if you wanna
tackle it;)
>
> Any advice is much appreciated as I'm a noob and still learning. Thanks!
Great! Keep up asking more!
Cheers,
/Tobias
>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
autobahnws+...@googlegroups.com
> <mailto:
autobahnws+...@googlegroups.com>.
> For more options, visit
https://groups.google.com/d/optout.