2012-04-02 17 views
0

まず、すばらしいチャンネルAPIのMoisheに感謝します。 私はGoogle Channel APIのドキュメントにある簡単なシナリオを実行しています。私が直面している問題は、チャンネルが開かれた後すぐに閉鎖されるということです。チャンネルapi公開後すぐにGAEチャンネルが閉じられる

/* Client Side */ 
public class Feed extends HttpServlet { 


private static String feed= 
    "<html>" + 
    "<head>" + 
    "<title>Login</title>" + 
    "<script type=\"text/javascript\" src="/_ah/channel/jsapi\"></script>" + 
    "</head>" + 
    "<body>" + 
    "Feed" + 
    "<script>" + 
    "channel=new goog.appengine.Channel('{{ token }}');" + 
    "socket=channel.open();" + 
    "socket.onOpen=alert(\"channel opened");" + 
    "socket.onMessage=alert(\"New Message\");" + 
    "socket.onClose=alert(\"Socket Closed\");" + 
    "socket.onError=alert(\"Error\");" + 
    "</script>" + 
    "</body>" + 
    "</html>";" 

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{ 

    ChannelService channelservice=ChannelServiceFactory.getChannelService(); 
    String token=channelservice.createChannel("sample"); 
    feed = feed.replaceAll("\\{\\{ token \\}\\}", token); 
    res.setContentType("text/html"); 
    res.getWriter().write(feed); 
} 

} 

/* Server Side*/ 

public class QuestAsk extends HttpServlet{ 

    public void doPost(HttpServletRequest req, HttpServletResponse resp) 
    { 
     ChannelService channelService=ChannelServiceFactory.getChannelService(); 
     channelService.sendMessage(new ChannelMessage("sample","sample message")); 
    } 
} 

私はフィードにGETリクエストを発行します。

それは、未定義のメッセージが受信された後にチャンネルオープンが表示されたときです - >チャンネルクローズ - >チャンネルエラーです。

明らかに、私はここで何かを見落としています。もし誰かがそれを指摘できれば非常に感謝します。助けてくれてありがとう。

よろしく

JR

答えて

1

私が見る二つの問題があります。

まず、開く時などには時価総額を持っていないので、あなたは、ソケットに間違った値を代入しています。あなたはsocket.onopen、socket.onmessage、socket.oncloseとsocket.onerrorを使うべきです。

第二に、あなたはsocket.onOpenなどに警告するための呼び出し()の結果を代入している代わりに、あなたはこのような何かを行う必要がありますので、これらの関数に機能を割り当てたい:

socket.onopen = function() {alert('Channel opened.');}; 
// etc 

これはあなたのコードを修正すると思います。

+0

ありがとうMoishe。それはうまくいった!大文字の誤りでした。それを指摘してくれてありがとうございます。 – user1302884

関連する問題