While you seek to establish a two-way communication between a browser's JavaScript and a TCP socket hosted by a .NET application, the current landscape of web technologies poses challenges.
As of now, popular browsers lack a standardized socket API for JavaScript. However, there are promising developments underway. The Raw Sockets API, which would allow direct socket manipulation, is currently in its draft stage.
Although the Raw Sockets API remains in flux, experimental support for TCP sockets has emerged in the Chrome browser. To leverage these features, enable the "experimental" flag in your Chrome extension's manifest. The following code snippet illustrates how to create and connect a TCP socket:
chrome.experimental.socket.create('tcp', '127.0.0.1', 8080, function(socketInfo) {
chrome.experimental.socket.connect(socketInfo.socketId, function (result) {
if (result) {
chrome.experimental.socket.write(socketInfo.socketId, "Hello, world!");
}
});
});
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3