这是一个非常复杂和适当的问题,所以对于我需要做的事情可能没有一个现实的答案.

我有一个使用无线接收器的任务,需要的不仅仅是jQuery的get / post功能.

由于跨域问题,这个jQuery得到了在Aptana IDE中创建的Adobe Air App中执行.

它必须是adobe air,因为Web服务器不会接近无线接收器最终连接的位置.

所以我需要一个可以与2KNow Renaissance无线接收器通信的应用程序.

我已经创建了一个应用程序来完成一些通信.这是我到目前为止可以采取的步骤.

>连接到接收器
>查看有多少手持设备连接到接收器
>然后应该有一些来回传播,至少在我的知识中,这在ajax中并不容易.

这是我一直在使用的代码,这是关于第24版,这是我已经得到的.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>2KNow Wireless Communicator</title>
</head>
<body>
<h1>Current Status/Prograess</h1>

<!--- step 1. is server connected --->
<div id="server_status" style="font-size:12px;"></div>

<!--- step 2. list number of devices connected --->
<div id="device_count" style="font-size:12px;"></div>
<div id="device_info" style="font-size:12px;"></div>

<!--- step 3.a Service Handler handler status / csh = Service Handler handler --->
<div id="csh_status" style="font-size:12px;"></div>

<!--- step 3.b disconnect status handler handler of many handlers --->
<div id="dis_status" style="font-size:12px;"></div>

<!--- step 4. test sending a question to a device --->
<div id="post_results" style="font-size:12px;"></div>

<!-- load the local jquery -->
<script type="text/javascript" src="lib/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="lib/jquery/json_parse.js"></script>
<script type="text/javascript" src="lib/jquery/jparse.min.js"></script>
<script type="text/javascript" src="lib/air/AIRAliases.js"></script>
<script type="text/javascript" src="lib/air/AIRIntrospector.js" />
<!-- Include service monitor framework -->
<script type="application/x-shockwave-flash" src="lib/air/servicemonitor.swf"></script>


<script type="text/javascript">
function watch_connection() {
    // do ajax get
    $.ajax({
        type: "GET",datatype: "xml",url: "http://my_ip_address:port/Services/ConnectServiceHandler",success: function(response){
            $('#post_results').html(response);
        },error:function (xhr,ajaxOptions,thrownError){
            $('#post_results').html("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
        }
    });
    setTimeout(function(){watch_connection;},100);
}

function disconnect_service_handler() {

    // step 1. create xml document of data to send
    var xml_string = '<data><disconnect_handler service="64"/></data>';

    // step 2. post this to the registration service
    $.ajax({
        type: "POST",url:"http://my_ip_address:port/Services/disconnectServiceHandler",data: xml_string,beforeSend: function(xhr){
               xhr.withCredentials = true;
        },timeout: (2 * 1000),success: function(response){

            // parse the response
            $(response).find("status").each(function() {
                // get the status code
                var disconnect_status = $(this).attr('code');

                if (disconnect_status == 200) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [200 disconnected]');

                    // call connection using new guid
                    var my_guid = guid();
                    connect_service_handler(my_guid);
                }

                if (disconnect_status == 304) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [304 No handler found]');
                }


                if (disconnect_status == 400) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [400 Bad Request]');
                }

                if (disconnect_status == 401) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [401 Not Found]');
                }

                if (disconnect_status == 500) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [500 Internal Server Failure]');
                }

                if (disconnect_status == 501) {
                    // change status bar message
                    $('#dis_status').html('disconnecting: [503 Service Unavailable]');
                }


            });


        },thrownError){
            $('#dis_status').html('disconnecting: [disconnect Failure]');
        }

    });
}
function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function connect_service_handler(my_guid) {

    // step 1. create xml document of data to send
    var xml_string = '<data><connect_handler service="64"><application id="'+my_guid+'" name="MikesBigEar" /></connect_handler></data>';

    // step 2. post this to the registration service
    $.ajax({
        type: "POST",url:"http://my_ip_address:port/Services/ConnectServiceHandler",success: function(response){

            // parse the response
            $(response).find("status").each(function() {

                // get the status code
                var connection_status = $(this).attr('code');

                if (connection_status == 200) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [200 Connected]');
                    // keep connection open keep socket alive
                    // sends http request to us via post
                    // sends the incoming request id and device address back to make sure it goes to the correct device
                    // ask for user id or user authentication
                    // for user authentication can either use built-in user authentication or ask a question
                    // http 1.1 keep alive header
                    $('#post_results').html('Attempting to check for next piece of data...');
                    watch_connection();
                }

                if (connection_status == 303) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [303 The handler is assigned to another application]');
                    var my_guid = guid();
                    connect_service_handler(my_guid);
                }

                if (connection_status == 400) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [400 Bad Request]');
                    disconnect_service_handler();
                }

                if (connection_status == 401) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [401 Not Found]');
                    disconnect_service_handler();
                }

                if (connection_status == 500) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [500 Internal Server Failure]');
                    disconnect_service_handler();
                }

                if (connection_status == 501) {
                    // change status bar message
                    $('#csh_status').html('Service Handler: [501 Service Unavailable]');
                    disconnect_service_handler();
                }


            });

            // pass the xml to the textarea
            // $('#process').val('ConnectServiceHandler');
            // $('#show_errors_here').val(response);

        },thrownError){
            $('#csh_status').html('Service Handler: [Connection Failure]');
            // alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
            // alert("responseText: "+xhr.responseText);
            // alert(xhr.status);
            // alert(thrownError);
        }

    });

    // set timed re-check and store it
    // setTimeout(function(){connect_service_handler(my_guid);},8000);


}

function get_device_count(my_guid) {
    // get the total number of devices

    // default receiver status
    var receiver_status = '';


    $('#device_count').html('Device Count: [Checking...]');
    $('#device_info').html('');

    // get the wireless receiver status via ajax xml
    $.ajax({
        type: "GET",url:"http://my_ip_address:port/Services/GetDevices",success: function(response){

            $(response).find("status").each(function() {
                // get the status code
                var receiver_status = $(this).attr('code');

                if (receiver_status == 200) {
                    // change status bar message
                    $('#device_count').html('Device Count: [200 Connected]');
                }

                if (receiver_status == 400) {
                    // change status bar message
                    $('#device_count').html('Device Count: [400 Bad Request]');
                }

                if (receiver_status == 401) {
                    // change status bar message
                    $('#device_count').html('Device Count: [401 Not Found]');
                }

                if (receiver_status == 500) {
                    // change status bar message
                    $('#device_count').html('Device Count: [500 Internal Server Failure]');
                }

                if (receiver_status == 501) {
                    // change status bar message
                    $('#device_count').html('Device Count: [501 Service Unavailable]');
                }


            });

            var device_count = 0;

            // add to div
            $('#device_info').append('<ul style="font-size:10px;">');

            $(response).find("device").each(function() {

                // get each property
                var device_status = $(this).attr('status');
                var short_address = $(this).attr('short_address');
                var mac_address = $(this).attr('mac_address');
                var pan_id = $(this).attr('pan_id');
                var type = $(this).attr('type');

                device_count = device_count + 1;

                // get session data
                $(this).find("session").each(function() {

                    // get session data
                    var created_date = $(this).attr('date');
                    var created_time = $(this).attr('time');

                });

                $('#device_info').append('<li style="list-style:none;">Device #'+device_count+'<ul>');

                // add list item
                $('#device_info').append('<li> Mac Address: ['+mac_address+']</li>');
                $('#device_info').append('<li> Short Address: ['+short_address+']</li>');
                $('#device_info').append('<li> Pan ID: ['+pan_id+']</li>');

                $('#device_info').append('</ul></li><br/>');

                // send request to this device
                // post_live_activity(mac_address,my_guid);



            });

            // end list
            $('#device_info').append('</ul>');

            if (device_count === 0) {
                $('#device_count').html('Device Count: [0 Devices Found]');
            } else if (device_count > 0) {
                $('#device_count').html('Device Count: [' + device_count + ' Devices Found]');
            }


        },thrownError){
            $('#device_count').html('Device Count: [Connection Failure]');
            // alert(xhr.status);
            // alert(thrownError);
        }
    });

    // set timed re-check and store it
    setTimeout(function(){get_device_count(my_guid);},13000);
}
function get_server_status(my_guid) {

    // default receiver status
    var receiver_status = '';

    // get the Renaissance Wireless Server via ajax xml
    $.ajax({
        type: "GET",url:"http://my_ip_address:port/Services/GetAccesspoints",success: function(response){

            $(response).find("status").each(function() {
                // get the status code
                var receiver_status = $(this).attr('code');

                if (receiver_status == 200) {

                    // change status bar message
                    $('#server_status').html('Renaissance Wireless Server: [200 Connected]');

                    // step 2. get device count
                    get_device_count(my_guid);

                    // step 3.part 1 get the guid to be used as the application id
                    // var my_guid = guid();

                    // step 3. part 2 connect to a service handler whatever that means
                    connect_service_handler(my_guid);

                }

                if (receiver_status == 400) {

                    // change status bar message
                    $('#server_status').html('Renaissance Wireless Server: [400 Bad Request]');

                    // set timed re-check and store it
                    setTimeout(function(){get_server_status(my_guid);},12300);

                }

                if (receiver_status == 401) {

                    // change status bar message
                    $('#server_status').html('Renaissance Wireless Server: [401 Not Found]');

                    // set timed re-check and store it
                    setTimeout(function(){get_server_status(my_guid);},12300);
                }

                if (receiver_status == 500) {

                    // change status bar message
                    $('#server_status').html('Renaissance Wireless Server: [500 Internal Server Failure]');

                    // set timed re-check and store it
                    setTimeout(function(){get_server_status(my_guid);},12300);

                }

                if (receiver_status == 501) {

                    // change status bar message
                    $('#server_status').html('Renaissance Wireless Server: [503 Service Unavailable]');

                    // set timed re-check and store it
                    setTimeout(function(){get_server_status(my_guid);},12300);

                }
                // pass the xml to the textarea
                // $('#process').val('GetAccesspoints');
                // $('#show_errors_here').val(response);

            });

        },thrownError){
            $('#server_status').html('Renaissance Wireless Server: [Connection Failure]');
            // alert(xhr.status);
            // alert(thrownError);
        }
    });

    // set timed re-check and store it
    // setTimeout(function(){get_server_status(my_guid);},12300);
}

$(document).ready(function() {

    // step 3.part 1 get the guid to be used as the application id
    var my_guid = guid();

    // step 1 validate
    get_server_status(my_guid);

    // step 2. get device count
    get_device_count();

    // step 3.part 1 get the guid to be used as the application id
    // var my_guid = guid();

    // step 3. part 2 connect to a service handler whatever that means
    // connect_service_handler(my_guid);


});
</script>
</body>
</html>

我的问题是,我应该使用不同的jquery插件,还是我接近这个错误?

谢谢…

解决方法

我不完全理解这个问题,所以提出建议有点棘手,但至少可以帮助解决一些不同的交通问题.

要求jQuery进行套接字通信是我所知道的jQuery范围之外的. jQuery实际上只是使用XMLHttpRequest,它不适用于持久套接字.

想法1

那么使用ActionScript Socket类呢
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/Socket.html

你可以在你的html页面中嵌入flash电影并从javascript调用它
http://www.hariscusto.com/programming/communication-between-javascript-and-actionscript-as3-and-vice-versa/

想法2

您还可以考虑Web服务器上的node.js和大型socket.io模块,以利用空中的websockets,然后在air客户端和服务器之间进行双向通信.除服务器端支持外,socket.io还有一个很棒的浏览器客户端.见http://socket.io/

这是一篇关于联邦快递技术博客的一篇有趣的帖子,关于将jQuery与socket.io和node.js一起使用 – http://spiritconsulting.com.ar/fedex/2010/11/events-with-jquery-nodejs-and-socket-io/

创意3(新)

html air开发人员可以使用air javascript套接字类.我刚刚在这里偶然发现:

主页/ HTML开发人员指南,用于Adobe AIR /网络和通信

http://help.adobe.com/en_US/air/html/dev/WSb2ba3b1aad8a27b0-181c51321220efd9d1c-8000.html

根据您的需要,有几种不同的套接字apis

如何在jQuery中使用套接字?的更多相关文章

  1. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. 关于h5中的fetch方法解读(小结)

    这篇文章主要介绍了关于h5中的fetch方法解读(小结),fetch身为H5中的一个新对象,他的诞生,是为了取代ajax的存在而出现,有兴趣的可以了解一下

  3. ios – 使用NSURLSession获取JSON数据

    我试图从谷歌距离api使用NSURLSession获取数据,但如下所示,当我打印响应和数据时,我得到的结果为NULL.可能是什么问题?

  4. ios – 错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:禁止

    任何人都可以帮我解决以下错误–>在AFNetworking2.5中使用“删除”方法时出错解决方法我发现,如果我的手机时钟不同步……它不允许我更新…也许检查你的手机设置到正确的时间“自动区”,看看是否有效…

  5. iOS网页/原生应用Facebook登录弹出 – 失败?

    如果我重新启动app/web-app,用户将自动登录,并重定向到成功页面.我认为是导致问题的原因当您在Firefox/Chrome/Safari浏览器中运行网页时,Facebook登录对话框会弹出一个弹出窗口或另一个选项卡.我相信这是这个弹出页面的一个问题,以及当成功登录时Javascript如何与自身通信.window.close的东西没有返回的根页面…失败的解决方法由于应用程序挂在前面提到的URL上,我决定在shouldStartLoadWithRequest(…)中添加if语句以强制UIWebvie

  6. ios – 来自UIAlertController的self.navigationController?.popViewControllerAnimated

    我是新手,但我想我已经掌握了它.这让我的进步很难过.我想要做的是当我们无法找到他的查询的相关数据时向用户抛出错误消息,然后继续将他带回到之前的ViewController.但是,我在这方面遇到了麻烦.在我添加操作的行上,我收到以下错误:’UIViewController?’不是Void的子类型我该怎么做呢?

  7. ios – Watchkit新会话不起作用

    我的手表扩展中有两个视图控制器.每当我打电话时我只得到第一个视图控制器的响应,并在第二个viewcontroller中得到错误WCSession在app和watch扩展中启动.任何建议?

  8. 使用Firebase iOS Swift将特定设备的通知推送到特定设备

    我非常感谢PushNotifications的帮助.我的应用聊天,用户可以直接向对方发送短信.但是如果没有PushNotifications,它就没有多大意义.它全部设置在Firebase上.如何将推送通知从特定设备发送到特定设备?

  9. ios – 保存从查询中获取的用户的属性(即不在currentUser上)

    我有兴趣根据currentUser执行的操作将属性保存到数据库中的用户.基于以下代码,我收到错误消息“除非已通过logIn或signUp验证用户,否则无法保存用户”我想知道是否有一个解决方法,我可以将属性保存到foundUser,而无需登录该用户.谢谢你的帮助!解决方法如果要更新当前不是登录用户的用户,则需要使用主密钥调用Parse.您可以从CloudCode执行此操作;并从您的iOS项目中调用它;

  10. 在iOS中使用NSJSONSerialization进行JSON解析

    解决方法首先在您的JSON响应字典中,在“RESPONSE”键下,您有一个数组而不是字典,该数组包含字典对象.所以要提取用户名和电子邮件ID,如下所示

随机推荐

  1. jquery-plugins – 是否可以使用猫头鹰旋转木马实现循环/无限轮播?

    我正在使用猫头鹰旋转木马,它的工作完美,除了它不支持循环/无限滚动.我没有搜索google和stackoverflow的想法,没有运气.有没有人在猫头鹰旋转木马上实现圆形/无限滚动?

  2. jQuery动态输入字段焦点

    我想使用以下jQuery向我的页面动态添加一个输入字段:在这样做之后,我希望输入字段具有闪烁的文本光标的焦点,所以我想在创建后立即输入.有人可以告诉我我该怎么办?

  3. jquery – 为什么$(window).height()这样错了?

    我试图获取当前浏览器的视口高度,使用但我得到的价值观太低了.当视口高度高达850px时,我从height()获取大约350或400像素的值.这是怎么回事?

  4. jquery – 如果在此div之外和其他draggables内部(使用无效和有效的还原选项),则可拖动恢复

    例如这样但是由于明显的原因,这不行.我可以说这个吗?

  5. 创建一个jQueryUI 1.8按钮菜单

    现在jQueryUI1.8已经出来了,我正在浏览更新,并且遇到了新的Buttonwidget,特别是SplitButtonwithadropdown的演示之一.这个演示似乎表明Buttonwidget可以在这里创建一个下拉菜单.作为讨论的问题,我想知道使用这个新的Button小部件来创建一个下拉菜单有什么方法.干杯.解决方法您必须在按钮下方列出一个列表,方式类似于此处为自动完成提供的演示:http

  6. 灰色divs使用JQuery

    我试图使用这个代码:为了淡出一大堆名为MySelectorDiv的div,唯一的是,它只会淡出第一个而不是所有的div,为什么呢?

  7. 使用jQuery动态插入到列表中

    我有两个订单列表在彼此旁边.当我从一个列表中选出一个节点时,我想按照字母顺序插入到另一个列表中.抓住的是我想要把一个元素放在另一个列表中,而不刷新整个列表.奇怪的是,当我插入到右边的列表中,它工作正常,但是当我插入到左边的列表中时,顺序永远不会出来.我也尝试将所有内容读入数组,并将其排序在一起,以防止children()方法没有按照显示顺序返回任何东西,但是我仍然得到相同的结果.这是我的jQuer

  8. 没有回应MediaWiki API使用jQuery

    我试图从维基百科获取一些内容作为JSON:但我没有回应.如果我粘贴到浏览器的地址栏,就像我得到预期的内容.怎么了?解决方法您需要通过添加&callback=?来触发具有$.getJSON()的JSONP行为?在querystring上,像这样:Youcantestithere.没有使用JSONP,你正在击中same-originpolicy,阻止XmlHttpRequest获取任何数据.

  9. jQuery Ajax请求每30秒

    我有这段代码,但是有些人在我的网站上的值可能会改变.我需要每30秒钟更新一次#financediv.这可以做吗解决方法您可以将代码放在单独的函数中,如下所示:然后每30秒建立一个定时器调用该函数:祝你好运!总结以上是DEVMAX为你收集整理的jQueryAjax请求每30秒全部内容。如果觉得DEVMAX网站内容还不错,欢迎将DEVMAX网站推荐给好友。

  10. jquery – keypress事件在IE和Chrome中不工作,但在FF工作

    任何想法为什么会这样发生?我通常认为Chrome会更加宽容代码?这是我的按键键.我错过了什么吗?右图();和leftimage();是应该工作的功能,因为我在其他地方使用这些功能谢谢您的帮助!

返回
顶部