Connecting to TCP Socket from browser using javascript
http://stackoverflow.com/questions/12407778/connecting-to-tcp-socket-from-browser-using-javascript
You can use HTML5 Web Sockets:
http://www.html5rocks.com/en/tutorials/websockets/basics/
++++++++++++++++++++++++++++++++++
阅读(95) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
You can use HTML5 Web Sockets:
点击(此处)折叠或打开
-
var connection = new WebSocket('ws://IPAddress:Port');
-
connection.onopen = function () {
-
connection.send('Ping'); // Send the message 'Ping' to the server
- };
Introducing WebSockets: Bringing Sockets to the Web
++++++++++++++++++++++++++++++++++
See jsocket. Haven't used it myself. Been more than 3 years since last update (as of 26/6/2014).
From the documentation:
点击(此处)折叠或打开
-
<script type='text/javascript'>
-
// Host we are connecting to
-
var host = 'localhost';
-
// Port we are connecting on
-
var port = 3000;
-
-
var socket = new jSocket();
-
-
// When the socket is added the to document
-
socket.onReady = function(){
-
socket.connect(host, port);
-
}
-
-
// Connection attempt finished
-
socket.onConnect = function(success, msg){
-
if(success){
-
// Send something to the socket
-
socket.write('Hello world');
-
}else{
-
alert('Connection to the server could not be estabilished: ' + msg);
-
}
-
}
-
socket.onData = function(data){
-
alert('Received from socket: '+data);
-
}
-
-
// Setup our socket in the div with the id="socket"
-
socket.setup('mySocket');
- </script>
相关热门文章
给主人留下些什么吧!~~
评论热议