Java and Javascript Socket Issue -


i'm developing chrome-extension should communicate java written process using sockets. testing i've tried following code , excepted output string ping.

java code :

    try {         serversocket = new serversocket(port_number); //port number 1025         serversocket.setsotimeout(0); // no timeout         while(true){             socket socket = serversocket.accept();             bufferedreader in = new bufferedreader(new inputstreamreader(socket.getinputstream()));             string line;             while ((line = in.readline()) != null){                 system.out.println(line);             }         }      } catch (ioexception e) {         system.out.println("port connection problem");     } 

js code following :

var connection = new websocket('ws://127.0.0.1:1025');  connection.onopen = function () {   connection.send('ping'); // send message 'ping' server }; 

the output :

get / http/1.1 upgrade: websocket connection: upgrade host: 127.0.0.1:1025 origin: http://www.reddit.com pragma: no-cache cache-control: no-cache sec-websocket-key: ocm8qwpqej2lps7qjlsohw== sec-websocket-version: 13 sec-websocket-extensions: permessage-deflate; client_max_window_bits, x-webkit-d eflate-frame user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/36.0.1985.143 safari/537.36 

not data above, didn't ask for, not message "ping" sent using socket. i'd grateful if tell me doing wrong , point me solution,thanks in advance.

you not implementing websocket protocol server in java, simple telnet-like server.

the browser tries establish connection per protocol, sending http upgrade request getting, not receive expected response.

as consequence, onopen event never triggers, browser's perspective did not establish connection.

advice: not "reinvent wheel" , use ready websocket library java, unless you're doing learn.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -