- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个非常复杂且小众的问题,因此对于我需要做的事情可能没有一个现实的答案。
我有一个使用无线接收器的任务,它需要的不仅仅是 jQuery 的获取/发布功能。
由于跨域问题,此 jQuery get 在 Aptana IDE 中创建的 Adobe Air 应用程序内执行。
它必须是 adobe air,因为网络服务器不会靠近无线接收器最终连接的位置。
所以我需要一个可以与 2Know Renaissance 无线接收器通信的应用程序。
我创建了一个应用程序,可以很好地进行一些通信。以下是到目前为止我可以执行的步骤。
这是我一直在使用的代码,这是关于第 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",
datatype: "xml",
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]');
}
});
},
error:function (xhr, ajaxOptions, 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",
datatype: "xml",
url:"http://my_ip_address:port/Services/ConnectServiceHandler",
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 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);
},
error:function (xhr, ajaxOptions, 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",
beforeSend: function(xhr){
xhr.withCredentials = true;
},
timeout: (2 * 1000),
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]');
}
},
error:function (xhr, ajaxOptions, 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",
timeout: (2 * 1000),
beforeSend: function(xhr){
xhr.withCredentials = true;
},
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);
});
},
error:function (xhr, ajaxOptions, 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 插件,还是我处理这个问题是错误的?
谢谢...
最佳答案
我正在为 socket.io 开发一个 jQuery 插件,我认为它可能会帮助你:
https://github.com/williscool/jquery-socket.io
我已经开发一个通过 socket.io 使用 Web 套接字的应用程序有一段时间了,它运行得很好。
检查一下并告诉我您的想法。
关于jquery - 如何在 jQuery 中做套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5262079/
我有一个关于 JavaScript 语法的问题。实际上,我在自学 MEAN 堆栈教程时想出了编码(https://thinkster.io/mean-stack-tutorial#adding-aut
在我的书中它使用了这样的东西: for($ARGV[0]) { Expression && do { print "..."; last; }; ... } for 循环不完整吗?另外,do 的意义何
我已经编写了读取开关状态的代码,如果按 3 次 # 则退出。 void allkeypadTest(void) { static uint8_t modeKeyCount=0; do
因此,对于上周我必须做的作业,我必须使用 4 个 do-while 循环和 if 语句在 Java 中制作一个猜谜游戏。我无法成功完成它,类(class)已经继续,没有为我提供任何帮助。如果有人可以查
int i=1,j=0,n=10,k; do{ j+=i; i<<1; printf("%d\n",i); // printf("%d\n",12<<1); }while
此代码用于基本杂货计算器的按钮。当我按下按钮时,一个输入对话框会显示您输入商品价格的位置。我遇到的问题是我无法弄清楚如何获得 do ... while 循环以使输入对话框在输入后弹出。 我希望它始终恢
当我在循环中修改字符串或另一个变量时,它的条件是否每次都重新计算?或者在循环开始前一次 std::string a("aa"); do { a = "aaaa"; } while(a.size<10)
我刚刚写了这个,但我找不到问题。我使用代码块并编写了这个问题 error: expected 'while' before '{' token === Build finished: 1 errors
do { printf("Enter number (0-6): ", ""); scanf("%d", &Num); }while(Num >= 0 && Num 表示“超过”,<表
我有一个包含 10 个项目的 vector (为简单起见,所有项目都属于同一类,称其为“a”)。我想要做的是检查“A”不是 a) 隐藏墙壁或 b) 隐藏另一个“A”。我有一个碰撞函数可以做到这一点。
嗨,这是我的第二个问题。我有下表 |-----|-------|------|------| |._id.|..INFO.|.DONE.|.LAST.| |..1..|...A...|...N..|.
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: Why are there sometimes meaningless do/while and if/e
来自 wikibook在 F# 上有一小部分它说: What does let! do?# let! runs an async object on its own thread, then it i
我在 Real World Haskell 书中遇到了以下函数: namesMatching pat | not (isPattern pat) = do exists do
我有一个类似于下面的用例,我创建了多个图并使用 gridExtra 将它们排列到一些页面布局中,最后使用 ggsave 将其保存为 PDF : p1 % mutate(label2
当我使用具有 for 循环的嵌套 let 语句时,如果没有 (do (html5 ..)),我将无法运行内部 [:tr]。 (defpartial column-settings-layout [&
执行 vagrant up 时出现此错误: anr@anr-Lenovo-G505s ~ $ vagrant up Bringing machine 'default' up with 'virtua
# ################################################# # Subroutine to add data to the table Blas
我想创建一个检查特定日期格式的读取主机。此外,目标是检查用户输入是否正确,如果不正确,则提示应再次弹出。 当我刚接触编程时,发现了这段代码,这似乎很合适。我仍然在努力“直到” do {
我关注这个tutorial在谷歌云机器学习引擎上进行培训。我一步一步地跟着它,但是在将 ml 作业提交到云时我遇到了错误。我运行了这个命令。 sam@sam-VirtualBox:~/models/r
我是一名优秀的程序员,十分优秀!