Coder Social home page Coder Social logo

Comments (11)

MatzElectronics avatar MatzElectronics commented on August 17, 2024

And receive base64 chars and decode them.

from blocklypropclient.

zfi avatar zfi commented on August 17, 2024

@PropGit Can you fit this into you build schedule soon? We want to wrap up the loose ends on the BlockyProp constellation of projects prior to the beginning of the fall semester.

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

@MatzElectronics @zfi - I'm having problems with this. I think I'm encoding and transmitting the data properly, but it fails to appear on the terminal and the web client console complains

Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

when it tries to do c_buf = atob(e.data);

I've reverted to a hard-coded test with these python lines:

data = base64.b64encode('your name'.encode('ascii'))
socket.send(data)

as well as other incarnations, and I can see that the web client receives eW91ciBuYW1l but it fails to decode it.

On the console, I've also tried data = btoa('your name') and it sets data to "eW91ciBuYW1l" and doing data = atob(data) outputs "your name", so there's something else baffling me that's happening with the received data or data structure.

Maybe the data appears as a string to me but is coming across as bytes (or vice-versa, or utf-8 or something) and atob() can't handle it? Been searching but haven't found the answer.

from blocklypropclient.

MatzElectronics avatar MatzElectronics commented on August 17, 2024

from blocklypropclient.

MatzElectronics avatar MatzElectronics commented on August 17, 2024

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

It was worth a try, yes, but the .toString() addition didn't change the behavior at all.
Doing console.log(e.data) just before the conversion confirms that the correct string appears; no extra or fewer, or different characters.

I'll keep looking.

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

Using https://www.base64encode.org/ and https://www.base64decode.org/, I verified that "your name" and "eW91ciBuYW1l" match the encoding for all 8 input character sets given.

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

Tried this article and it's suggestion to use base64.encodestring() too... no luck.

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

I even tried converting it to a array buffer first, using this:
c_buf = atob(str2ab(c_buf));

that references this code:

// Converts String to ArrayBuffer.
var str2ab = function(str, len = null) {
// Convert str to array buffer, optionally of size len
  if (!len) {
    len = str.length;
  }
  var buf = new ArrayBuffer(len);
  var bufView = new Uint8Array(buf);
  for (var i = 0; i < Math.min(len, str.length); i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return buf;
};

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

Solved it- with the help of both of you @MatzElectronics and @zfi.

atob() does indeed accept a string and the Python code was indeed encoding correctly and sending it as a string (and the .onmessage() event's resulting e.data was indeed a string type). I verified this a few different ways last night and this morning.

@MatzElectronics's emailed code got me thinking differently (thank you!) and his follow-up statement "...make sure the connection string sent right at the beginning is also base64 encoded" ultimately made me realize what was happening... the connection statement was not encoded (my mistake) and the web client code was:

  1. complaining only about that connection statement transmission as being incorrectly encoded, not the many data transmissions following it (I misunderstood exactly what transmission it was choking on), and,
  2. it was not displaying anything on the terminal because the non-encoded connection statement was never found, so it ignored the rest.

No need for a custom atob function... it all works properly now.

I'll verify bi-directional function too before I finalize.

from blocklypropclient.

PropGit avatar PropGit commented on August 17, 2024

Fixed. Added in PR #105.

from blocklypropclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.