jsXMLSocket

MIT
JavaScript
跨平台
2012-03-16
小编辑

jsXMLSocket 是一个用来跟 Adobe Flash 的 XMLSocket 类进行通讯的 JavaScript 接口。

示例代码:

<html>
<head>
   
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
   
<script type="text/javascript" src="jsxmlsocket.js"></script>
   
<script type='text/javascript'>
       
// Host we are connecting to
       
var host = 'localhost';
       
// Port we are connecting on
       
var port = 8008;

       
var socket = new jsXMLSocket();

       
// When the socket is added the to document
        socket
.onReady = function() {
            socket
.connect(host, port);
            $
('#messages').append('Connecting to ' + host + ':' + port + '... ');
       
}

       
// Connection attempt finished
        socket
.onConnect = function(success, error) {
           
if(success) {
                socket
.send('init');
                $
('#messages').append('Connected.<br/>');
           
} else {
                $
('#messages').append('Connection failed.<br/>');
           
}
       
}

       
// Server closed socket
        socket
.onClose = function() {
            $
('#messages').append('Server disconnected.<br/>');
       
}

       
// Received data
        socket
.onData = function(data) {
            $
('#messages').append(data + '<br/>');
       
}

        $
(document).ready(function() {
           
// Setup our socket in the div with the id="socket"
            socket
.setup('#socket');
       
});
   
</script>
   
<title>jsXMLSocket</title>
</head>
<body>
   
<div id='socket'></div>
   
<h1>jsXMLSocket</h1>
   
<div id="messages"></div>
</body>
</html>

加载中

评论(0)

暂无评论

暂无资讯

暂无问答

暂无博客

返回顶部
顶部