views:

44

answers:

2

Hello, we wrote in C++ a screen sharing application based on sending screenshots.

It works by establishing a TCP connection btw the server and client, where the server forwards every new screenshot received for a user through the connection, and this is popped-up by the client.

Now, we are trying to host this on google app engine, and therefore need 'servlet'-ize and 'sandbox' the server code, so to implement this forwarding through HTTP requests.

I immagine the following: 1. Post request with the screenshot as multiple-data form (apache uploads ..). But now the server needs to contact the specified client (who is logged in) to send it/forward the screenshot. I'm not sure how to 'initiate' such connection from the servlet to the client. The client doesn't run any servlet environment (of course). I know HTTP 1.1 mantains a TCP connection, but it seems gapps won't let me use it.

1 approaches that comes to mind is to send a CONTINUE 100 to every logged in user at login, and respond with the screenshot once it arrives. Upon receival the client makes another request, and so on. an alternative (insipired from setting the refresh header for a browser) would be to have the app pool on a regular basis (every 5 secs).

+1  A: 

You're not going to be able to do this effectively on GAE.

Problem 1: All output is buffered until your handler returns.

Problem 2: Quotas & Limits:

Some features impose limits unrelated to quotas to protect the stability of the system. For example, when an application is called to serve a web request, it must issue a response within 30 seconds. If the application takes too long, the process is terminated and the server returns an error code to the user. The request timeout is dynamic, and may be shortened if a request handler reaches its timeout frequently to conserve resources.

Comet support is on the product roadmap, but to me your app still seems like a poor fit for a GAE application.

cope360
Okay, beside GAE within a Java EE container how do you achieve the expected behavior through HTTP requests/responses?
simpatico
Here's an article that may help get you started: http://www.ibm.com/developerworks/web/library/wa-cometjava/index.htmlYou may want to ask a new question tagged Java and not GAE.
cope360
A: 

Long Polling is the concept used for such asynchronous communications between server and client. In Long Polling, servlet keeps a map of client and associated messages. Key of Map being client id and value being list of messages to be sent to the client. When a client opens a connection with server (sends request to a servlet), the servlet checks the Map if there are any messages to be sent to it. If found, it sends the messages to the client exits from the method. On receiving messages, the client opens a new connection to the server. If the servlet does not find any messages for given client, it waits till the Map gets updated with messages for given client.

Tushar Tarkas
Long Polling will NOT work on GAE for reasons, see @cope360's answer (problem 2)
naikus
forgot to mention, the answer was in response to simpatico's comment.
Tushar Tarkas