Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send a large image buffer from client #204

Open
jsheffers opened this issue Dec 20, 2024 · 0 comments
Open

Unable to send a large image buffer from client #204

jsheffers opened this issue Dec 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jsheffers
Copy link

jsheffers commented Dec 20, 2024

When client.write() finally sends I get the following error. [RangeError: Property storage exceeds 196607 properties]. I'm then trying to send that data via your library. Do you see any issues here? I don't have control over the server, it's expecting a binary file not chunks of a binary file, so I don't thinking chunking is even an option here.

  const startImageTransfer = (connInfo) => {
    console.log("––––––– startImageTransfer() ––––––––");
    if (connInfo && imageData) {
      // console.log("Starting image transfer with connInfo:", connInfo);

      const header = JSON.stringify({
        num: 0,
        total: 1,
        fileLength: imageData.length,
        fileName: "something",
        fileType: "jpg",
        secKey: connInfo.key,
        version: "0.0.1",
      });

      const options = {
        port: parseInt(connInfo.port),
        host: connInfo.ip,
        reuseAddress: true,
      };

      const client = TcpSocket.createConnection(options, async () => {
        console.log("––––––– TCP connected! ––––––––");

        try {
          // Send header length (4 bytes)
          const headerBytes = Buffer.from(header, "utf8");
          const headerLength = Buffer.alloc(4);
          headerLength.writeUInt32BE(headerBytes.length);

          const combinedData = Buffer.concat([
            headerLength,
            headerBytes,
            imageData,
          ]);
          client.write(combinedData);
          console.log("Sent combined data:", combinedData);
          client.end();
        } catch (error) {
          console.error("Error sending data:", error);
        }
      });

      client.on("data", (data) => {
        console.log("TCP received:", data.toString());
      });

      client.on("error", (error) => {
        console.error("TCP Error:", error);
      });

      client.on("close", () => {
        console.log("TCP Connection closed");
      });
    } else {
      console.error("Missing connInfo or imageData");
    }
  };
@jsheffers jsheffers added the bug Something isn't working label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant