For establishing real-time communication between a browser and a TCP socket-based server application, you can explore two feasible methods:
1. XHR or WebSockets
Both XHR (XMLHttpRequest) and WebSockets facilitate real-time data transfer between a browser and a server. However, neither provides direct access to raw TCP sockets.
2. Chrome's Experimental TCPSocket API
Chrome provides an experimental TCPSocket API that enables developers to establish and manage raw TCP connections from browser applications. Here's an example:
chrome.experimental.socket.create('tcp', '127.0.0.1', 8080, function(socketInfo) {
chrome.experimental.socket.connect(socketInfo.socketId, function (result) {
chrome.experimental.socket.write(socketInfo.socketId, "Hello, world!");
});
});
Note: This API is only available for Chrome apps and requires enabling an experimental flag in the extension manifest.
Additional Information:
For further exploration of the TCPSocket API, refer to the provided links:
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