开发者

How would I share chat/sketches in real time on Android?

开发者 https://www.devze.com 2023-02-02 00:50 出处:网络
Imagine that I would like to do an app where users can chat, but visually - they would 开发者_如何学运维paint stuff on the screen. The screen would be split in half, and each participant would draw so

Imagine that I would like to do an app where users can chat, but visually - they would 开发者_如何学运维paint stuff on the screen. The screen would be split in half, and each participant would draw something on their half, and it would appear to the other participant.

Sketching on the touch screen should be pretty straightforward, also providing user with color/brush selection, eraser, etc. I would need to capture user input into some kind of messages, each of which would describe a sketch action that would need to be replayed on the remote participant.

But how would these two users communicate? I'm thinking about JSON+AppEngine+XMPP.

  • I would serialize the sketch actions from client A into JSON and push them onto AppEngine, that would store them. Is this approach - store stuff on server - better than P2P connection? It would possibly add significant lag due to phone A->AppEngine->phone B round-trip
  • How would client B retrieve the message? I can't have constant open connection to AppEngine. There is something about push notifications in this question. If XMPP doesn't work, would it need to poll the server?


This is a very broad question which has many different answers. If it were up to me I'd probably go with polling. You don't want a constant connection and using something like Google's Cloud2Device might be a little bit of overkill for something like this. I'd imagine it'd look something like this -

  • Client A and Client B initiate a connection with each other. They both receive a session token.
  • Client A draws something on screen. The points drawn are sent to a central server and stored along with the session token.
  • Client B polls central server for new points, passing along his session token.
  • The points retrieved are drawn on Client B's screen.
  • Previous stored points are removed.
  • Repeat.

As for specific technology, that's really up to you and what you're comfortable with. The easiest may be to use a central database server to store your points and generate your session tokens.


If you are planning on using App Engine, you would probably be using the Channel API, as described here.

The Channel API creates a persistent connection between your application and Google servers, allowing your application to send messages to JavaScript clients in real time without the use of polling. This is useful for applications that are designed to update the user about new information immediately or where user input is immediately broadcast to other users. Some examples include collaborative applications, multi-player games, and chat rooms. In general, using Channel API is a better choice than polling in situations where updates can't be predicted or scripted, such as when relaying information between human users or from events not generated systematically.

0

精彩评论

暂无评论...
验证码 换一张
取 消