JavaScript failing to receive Java packets via Google Chrome Extension

JavaScript is failing to receive EiD values from Java to JavaScript. How can i fix it?

JavaScript, Google chrome extension:

port.onMessage.addListener(function(message) { // from .exe
  sendToWebSite(JSON.stringify(message));
}); 

Java sending the EiD data to JavaScript:

public static void sendMessage(String msgdata) {
    try {
      int dataLength = msgdata.length();
      System.out.write((byte) (dataLength & 0xFF));
      System.out.write((byte) ((dataLength >> 8) & 0xFF));
      System.out.write((byte) ((dataLength >> 16) & 0xFF));
      System.out.write((byte) ((dataLength >> 24) & 0xFF));

      // Writing the message itself
      System.out.write(msgdata.getBytes());
      System.out.flush();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, "error in sending message to JS");
    }
  }

msgdata = as below

Answers


Following works.

  String tmp = Beid.bid(); //big string with \n and hash picture:
  String[] output = tmp.split("picture:"); 
  tmp = output[0]; //how to avoid split picture:?

  tmp = tmp.replaceAll("(\r\n|\n)", "<br/>");
  sendMessage("{\"msg\" : \"" + tmp + "\"}");

EDIT:

  • Windows 10 it was not working because it had old Java, after installing Java 8 it worked.

Need Your Help

Executing multiple bat files with Visual basics

vb.net batch-file cmd

I'm working on a program created with Visual Studio 2013. The program does a few things and I'm nearly complete, but one last issue appears.

IOS NSDateFormatter Problems

ios datetime date nsdate nsdateformatter

We are building an app which requires the storage of a date for an entry on the device, the app will be international so we hit two dilema's / challenges.