I spent hours today and yesterday, in how to get Chrome native messaging with C# host. Tried again with Java Host, and the same error too. With the help for these questions, i make several tries, with no success:
C# native host with Chrome Native Messaging
Native messaging from chrome extension to native host written in C#
Very Slow to pass "large" amount of data from Chrome Extension to Host (written in C#)
Tried with VStudio 2017, 2019, with c# 4.7, c# client profile 4.0; With Java, tried with JRE 8, JRE 11, and the same error appears. With Python, the test succeeded, why ? (Binary mode works ?) The only solution acceptable from the Project Manager is C#...
static void Main(string[] args)
{
bool platform64 = true;
if (IntPtr.Size == 8)
platform64 = true;
else
platform64 = false;
logger.InfoFormat("Platform x64?: {0}", platform64);
logger.InfoFormat("Arguments:");
foreach (String arg in args)
{
logger.InfoFormat(" arg: {0}", arg);
}
JObject data;
while ((data = Read()) != null)
{
var processed = ProcessMessage(data);
SendMessage(processed);
if (processed["text"].Value<string>().Equals("exit"))
{
return;
}
}
}
public static JObject Read()
{
logger.Debug("Init Read()...");
var stdin = Console.OpenStandardInput();
var lengthBytes = new byte[4];
stdin.Read(lengthBytes, 0, 4);
var length = BitConverter.ToInt32(lengthBytes, 0);
logger.DebugFormat("Length of bytes...{0}", length);
var buffer = new char[length];
var input = "";
for (int i = 0; i < length; i++)
input += (char)stdin.ReadByte();
return JsonConvert.DeserializeObject<JObject>(input);
}
public static void SendMessage(JObject data)
{
var bytes = System.Text.Encoding.UTF8.GetBytes(data.ToString(Formatting.None));
var stdout = Console.OpenStandardOutput();
stdout.WriteByte((byte)((bytes.Length >> 0) & 0xFF));
stdout.WriteByte((byte)((bytes.Length >> 8) & 0xFF));
stdout.WriteByte((byte)((bytes.Length >> 16) & 0xFF));
stdout.WriteByte((byte)((bytes.Length >> 24) & 0xFF));
stdout.Write(bytes, 0, bytes.Length);
stdout.Flush();
}
From the docs in Google, with respect the binary format and the information from StackOverflow, does any knows what can make this works, and Google comunicate with the Host ?
Sample of sending native message (Direct):
chrome.runtime.sendNativeMessage('com.otisw.signer',
{ text: "list" },
function (response) {
console.log("Received " + response);
});