Click here to Skip to main content
15,868,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i am doing socket programming But getting error in response .
i am using this like to do socket programming
http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/[^]

But when i debug my program i am getting all data in my .java file in that method.
Java
private String buildLoadData(String _event, String _data) {
        String _d =  "javascript:WebSocket.on" + _event + "(" + 
                    "{"
                    + "\"_target\":\"" + webSocketId + "\"," + 
                    "\"_data\":'" + data + "'" + 
                    "}" + 
                ")";
        Logger.log(_d);
        return _d;
    }


Here is _d print ..

WebSocket.onmessage({"_target":"WEBSOCKET.54","data":'!!20W)0
(Note:  In open court at !#10W*.)0
THE COURT:  !$10W*I\'m !%10W+going !&10W+to !\'10W+re!(10W,serve !)10W,counsel !*10W,'})
---------------------------------

But from Html where i need data to show i call this java method.But i am getting only this result

Java
   var socket = new WebSocket('ws://192.168.1.3:8101/');

// push a message after the connection is established.
socket.onopen = function() {

    socket.send('Hello World')
};

// alerts message pushed from server
socket.onmessage = function(msg) {
//alert("TTTTT"+JSON.stringify(msg));
$(".test_h").val(JSON.stringify(msg)).keyup();
    console.log("TTTTT"+JSON.stringify(msg));
};

// alert close event
socket.onclose = function() {
    alert('closed');
}; 

In console i am getting this,....
    06-27 11:04:36.156: I/Web Console(924): TTTTT{"_target":"WEBSOCKET.54","data":"!!2"} at file:///android_asset/www/index.html:52
then after i am getting like this

     06-27 10:53:25.136: D/CordovaLog(871): Uncaught SyntaxError: Unexpected token ILLEGAL
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    it is printed again and again this message
    Uncaught SyntaxError: Unexpected token ILLEGAL at null:1
    ?How to remove this error.?
Posted
Updated 4-Jul-13 16:10pm
v2

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