Вы можете использовать HTML5 Web Sockets
:
var connection = new WebSocket('ws://IPAddress:Port');
connection.onopen = function () {
connection.send('Ping'); // Send the message 'Ping' to the server
};
http://www.html5rocks.com/en/tutorials/websockets/basics/
Ваш сервер также должен прослушиваться с сервера WebSocket, такого как pywebsocket, иначе вы можете написать свой собственный, как описано в Mozilla
Дополнительно:
Обновить : Из проекта W3C в январе 2016 года:
Это будет возможно через интерфейс навигатора, как показано ниже:
http://raw-sockets.sysapps.org/# interface-tcpsocket
https://www.w3.org/TR/tcp-udp-sockets/
navigator.tcpPermission.requestPermission({remoteAddress:"127.0.0.1", remotePort:6789}).then(
() => {
// Permission was granted
// Create a new TCP client socket and connect to remote host
var mySocket = new TCPSocket("127.0.0.1", 6789);
// Send data to server
mySocket.writeable.write("Hello World").then(
() => {
// Data sent sucessfully, wait for response
console.log("Data has been sent to server");
mySocket.readable.getReader().read().then(
({ value, done }) => {
if (!done) {
// Response received, log it:
console.log("Data received from server:" + value);
}
// Close the TCP connection
mySocket.close();
}
);
},
e => console.error("Sending error: ", e);
);