Note that there are some explanatory texts on larger screens.

plurals
  1. POWebsocket Java Server. Not sending message nor receiving
    primarykey
    data
    text
    <p>I'm trying to make a Java WebSocket server, nothing really complicated, just a little, ugly small server to try the websockets from the browser using the standard defined api.</p> <p>I've been reading the specification of the protocol and it's quite simple. I've made the handshake and apparently it's working. </p> <p>What I did with Java is: Opening a socket, receive the request from the <code>new Websocket("ws://...")</code> from the browser's JavaScript, send the server's response creating the "Sec-WebSocket-Accept". All these seems to be working! The google Chrome developers tools show me that the connection was successful... (here is the image)</p> <p><img src="https://i.imgur.com/jxYqZ.jpg" alt="connection"></p> <p>And also I made a <code>ws.onopen = function(ev){ alert("Opened!!");</code> and that works... (so the connection must be ok right?).</p> <p>But now, I'm trying to send data from the server to the browser or browser to server, but nothing happens...</p> <p>To send data from the browser to server I just do a <code>ws.send("datos");</code> and in the server I try to read this doing a <code>readLine(in)</code> being <code>in = clientSocket.getInputStream();</code>... But nothing... not working...</p> <p>And to send data from the server to the browser I do a <code>out.write(webSockFrame("data")getBytes())</code> but again... nothing happens in the browser... in the browser I'm waiting data doing a <code>ws.onmessage = function(ev){....}</code>...</p> <p>(The <code>webSockFrame(string)</code> function adds the two bytes that the standard requires, one at the beginning and one at the end of the string.)</p> <p>And I also tried to connect to the server using telnet (to check if the server was working ok), and it worked perfectly, everything, sending and receiving data from the telnet and from the server...</p> <p>What am I doing wrong?</p> <p>I'm using the last version of Chrome (14).</p> <p>I don't want to build a heavy concurrency server, just a little one to try this new technology.</p> <p>UPDATE: I don't know what else to try... I did a netstat -a to see if the connection is really active or is just an error of chrome, but for my surprise it exists and is opened until I close the webserver... I don't know why send and ws.onmessage doesn't work... </p> <p>UPDATE II: I made a change of a text on the event onopen, and the text change... and also made a onclose change of text and when I close the server the text changes... so the connection does exists and the onopen and onclose works perfectly... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload