Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to create a common chat room app in google app engine till now i'm able to create the token for the userid...i.e when user logs in with a name . a token is created for the name. which is being displayed in the text area
my problem is that after getting this token i'n not able to open the channel or use use the channel i'm stuck here form long time.


HTML
  <script type="text/javascript">

 $(document).ready(function(){
	 alert("doc");
	
$("#field1").hide();
 	
     $(".button").click(function(){
    $("#field2").hide();
    $("#field1").fadeIn(2500);
        var clientid = $("#textbox2").val();
        
        
			var form=$('#form1');
	
	$.get(form.attr('action'),$(form1).serialize(),function(data,status){
		
 alert(status);       
 			$('#display').val(" client id is "+clientid);
        	$('#display').val(" tok id is "+data.token);
        							}        
	
        	)
        	
        
       
	});<code></code>
 });
 </script>


This is my html(js or jquery) where i'm able to create the token by sending the clientid which is entered by the user and sending it to the servlet(chatroom.java)

Java
 package com.example.chatroom;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;

import com.google.appengine.api.channel.ChannelMessage;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.labs.repackaged.org.json.JSONObject;

@SuppressWarnings("serial")
public class ChatroomServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();
		try
		{
		String clientid = request.getParameter("clientid");
		ChannelService channelService = ChannelServiceFactory.getChannelService();

		String token = channelService.createChannel(clientid);
		
		System.out.println("token is ="+token);
		
		JSONObject job=new JSONObject();
		job.put("token",token);
		
		String jsondata=job.toString();
		
		out.write(jsondata);
		 }
		catch(Exception e)
		 {
	          e.printStackTrace();
	      }
		}
		}


this is my servlet where i'm able to create the token now my question is how to open this channel and use it to display(for now) connection established message .i need a little example for channel api working procedure .. waiting for the answers!!!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900