Skip to content

socket.write(byte[]) does not work #484

@cool2man

Description

@cool2man

My code looks like:

socket = new Socket(host, port);
streamOut = new BufferedOutputStream(socket.getOutputStream());
byte[] b = new byte[] { 0x33, 0x66, (byte) 0x99, (byte) 0xcc };
streamOut.write(b);

This results into sending ONE byte (which is 0x00) instead of the FOUR bytes.

Having a look into websock.js I noticed a problem in the following function:

function send(arr) {
    Util.Debug(">> send_array: " + arr);
    sQ = sQ.concat(arr);
    return flush();
}

sQ is an empty array, while arr is an Uint8Array. Therefore sQ.concat(arr) results into an array with ONE entry which is the complete Uint8Array arr (and not in an array with 4 entries).

I changed the send function for my testing:

function send(arr) {
    Util.Debug(">> send_array: " + arr);
    // sQ = sQ.concat(arr);
    for (var i=0; i<arr.length; i++) {
        sQ.push(arr[i]);
    }
    return flush();
}

I think, that doppio should take care, that the parameter "arr" is of type array and not Unint8Array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions