Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 2 of 2

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.

  2. #2
    derrick is offline Junior Member
    Join Date
    Feb 2011
    Posts
    2

    Default

    I think I'm having the same issue but with a C# server. My onmessage and onopen methods are not triggered when I send the header from the server. Here's my header from the server.

    HTTP/1.1 101 WebSocket Protocol Handshake
    Upgrade: WebSocket
    Connection: Upgrade
    Sec-WebSocket-Origin: chrome://newtab
    Sec-WebSocket-Location: my srever IP:8080
    I/�<�q�����A|E

    I'm using UTF8 when sending and receiving. Did you find a solution for the problem?.

Similar Threads

  1. Websocket Communication Problem
    By surajssoni in forum Plugins Troubleshooting
    Replies: 0
    Last Post: 01-12-2010, 04:11 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, 09: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
  •