Reading from sockets: data sent from an HTML client to a Neko Server


#1

In a windows implementation, I found the following code allowed me to read the test string below:

Client:

var socket = new Socket(); 
socket.connect("localhost", 1234);
socket.writeUTFBytes("test.¤");
Neko threadserver:

override function readClientMessage(c:Client, buf:Bytes, pos:Int, len:Int) {
    // find out if there's a full message, and if so, how long it is.
    trace("testing the string reading capability...");
	var complete = false;
    var cpos = pos;
    while (cpos < (pos+len) && !complete)
    {
     //check for a terminator symbol (¤) to signify complete message  
      complete = (buf.get(cpos) == 164);
      cpos++;
    }
    if ( !complete ) return null;

With an HTML implementation for the client, I found that the buffer, instead of returning the string, returns a lot of information about the browser being used.

“trace(buf);” gives:

GET / HTTP/1.1
HOST: localhost:1234
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; rv:61.0) Gecko/20100101 firefox 61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: n-US,en;q=0.5
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost:2000
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: (Some numbers/string)
DNT: 1
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-control: no-cache
Upgrade: websocket

What am I missing that allows me to access the string I sent?


#2

The packet you are receiving on server side is the HTTP message used for Websocket handshaking.
That’s because HTML5 only supports Websockets, so your server has to handle them.
You should find a few implementations of Haxe servers supporting Websockets on the Web, like this one :


#3

Thanks very much for your response. I learned a lot from reading that code, and also from this link, which I include to help future people that have the same issue.