Understanding Websockets/WAMP better

#1

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.

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 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?

Assuming I’m not missing anything, I then turned to reading about WAMP. 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?

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 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…

Any advice is much appreciated as I’m a noob and still learning. Thanks!

0 Likes

#2

Terence,

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

···

Am 22.05.2014 03:47, schrieb Terence Chow:

--
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.

0 Likes

#3

This is great Tobias! Thanks so much! I don’t have the experience unfortunately to tackle it, but maybe in the future I’d be open to contributing! Right now I think I’ll review the faye implementation and then see if I can transfer some of the code to the gem I am using (websocket-eventmachine-server which more active).

Thanks again this helped my understanding so much!

···

On Thu, May 22, 2014 at 4:53 AM, Tobias Oberstein tobias.o...@gmail.com wrote:

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):

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.

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.

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+unsubscribe@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Autobahn” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/Yt9QSaAlee0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to autobahnws+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#4

Hi Terence,

If you are willing to implement WAMPv2 in ruby, you might find my wamp-ruby branch useful.
I’ve created a skeleton which deals already with WAMP message serialization/deserialization, so it leaves you only to worry about the role implementations.

See my message here for more details.

בתאריך יום חמישי, 22 במאי 2014 19:17:05 UTC+3, מאת Terence Chow:

···

This is great Tobias! Thanks so much! I don’t have the experience unfortunately to tackle it, but maybe in the future I’d be open to contributing! Right now I think I’ll review the faye implementation and then see if I can transfer some of the code to the gem I am using (websocket-eventmachine-server which more active).

Thanks again this helped my understanding so much!

On Thu, May 22, 2014 at 4:53 AM, Tobias Oberstein tobia...@gmail.com wrote:

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):

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.

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.

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+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Autobahn” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/Yt9QSaAlee0/unsubscribe.

To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

0 Likes