Results 1 to 1 of 1

This is a discussion on Websocket Communication Problem within the Plugins Troubleshooting section, part of the Chrome Plugins category: I am writing a google chrome extension which will communicate with a server implemented on java and running on my ...


  1. #1
    surajssoni is offline Junior Member
    Join Date
    Dec 2009
    Posts
    3

    Default Websocket Communication Problem

    I am writing a google chrome extension which will communicate with a server implemented on java and running on my machine.

    I have the following code in background.html which is executed as soon as the extension opens:

    var ws = new WebSocket("ws://localhost:49731");
    console.log("Web Socket created with the state "+ ws.readyState);

    try {

    ws.onopen=function(){

    alert("Connection opened");};
    }

    catch (err) {
    console.log(err);
    }



    The following is the code for the java server:

    try{
    hearsay_socket = new ServerSocket(49731);
    System.out.println("Waiting on Accept");
    js_socket = hearsay_socket.accept();
    System.out.println("Handling client at " +
    js_socket.getInetAddress().getHostAddress() + " on port " +
    js_socket.getPort());
    out = new PrintWriter(js_socket.getOutputStream(),true);
    in = new BufferedReader(new InputStreamReader(js_socket.getInputStream()));
    System.out.println("Web socket Accepted");
    for(;
    {
    bufferedData= in.readLine();
    System.out.println(bufferedData);
    if(bufferedData.length()==0)
    {
    System.out.println("Breaking");
    break;
    }
    }
    }
    catch(UnknownHostException e)
    {
    System.err.println("Have no information about the host : localhost");
    System.exit(1);
    }
    catch(IOException e)
    {
    System.err.println("Couldn't establish communication");
    }



    handShake1 = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n"+
    "Upgrade: WebSocket\r\n"+
    "Connection: Upgrade\r\n";
    handShake2= "WebSocket-Origin: chrome-extension://jikhaebpllfkfacdccmeonpkpfcnldna\r\n"+
    "WebSocket-Location: ws:/"+js_socket.getLocalAddress()+":"+js_socket.getLoc alPort()+"\r\n\r\n";

    handShake2=handShake2.toLowerCase();
    System.out.println(handShake2);
    byte[] bytes1=handShake1.getBytes("ASCII");
    byte[] bytes2= handShake2.getBytes("ASCII");
    out.print(bytes1);
    out.print(bytes2);
    out.close();
    in.close();
    hearsay_socket.close();
    js_socket.close();
    }
    }


    I read almost all the documentations of websockets and websocket protocol but i did not find any glitch. Could anyone please help??

    Its urgent.

    P.S. : Also i am able to come out of accept() on the server side in java, so it atleast accepts the first part of the web protocol handshake, but somehow the second part i.e from server to the browser is not complete.
    Last edited by surajssoni; 01-13-2010 at 05:36 AM.

Similar Threads

  1. Websocket Communication Problem
    By surajssoni in forum Plugins Troubleshooting
    Replies: 1
    Last Post: 02-22-2011, 05:03 PM
  2. Websocket Communication Problem
    By surajssoni in forum Chrome Plugins
    Replies: 0
    Last Post: 01-12-2010, 02:49 PM
  3. Communication
    By Waha in forum Plugins Development
    Replies: 7
    Last Post: 10-14-2009, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •