咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

测试工具:
MQTTLens,MQTTBox

测试服务地址:

1
2
3
4
5
6
7
8
1. mosquitto
mqtt://test.mosquitto.org
ws://test.mosquitto.org:8080/mqtt (没连上)
测试页面:http://test.mosquitto.org/ws.html

2. eclipse
tcp://iot.eclipse.org
ws://iot.eclipse.org:80/ws

MQTT Client 比较多,各种语言都有开源项目,基本都是基于TCP/IP的,如Java/OC/Swift/nodejs/C/C++等。

H5上的js也可以使用MQTT,只不过是基于WebSocket,用法和其他语言的有一点点区别。

阅读全文 »

1
2
3
4
5
6
7
<script language="javascript">
function getarg(url){
arg=url.split("#");
return arg[1];
}
alert(getarg('http://www.iswtf.com/test.php#ID=58'));
</script>

昨天遇到这个问题:在A页面中通过location.href跳转到另一个B页面,此跳转地址是http://www.xyz.com/aa.html#bb.html?param=xxx 现在要怎么在B页面中取到param的值?现在的情况是跳到B页面后地址栏显示的就是http://www.xyz.com/aa.html#bb.html 后面的参数部分没有了,取到的参数值也是空的

搞了好久也没出来,最后问了大牛才发现我的基本功不行啊 理解就出错了,#后的内容都不会传到服务端的,所以到新页面看到的地址栏中就没有#后的参数,经大牛指点,把地址改为:
http://www.xyz.com/aa.html?param=xxx#bb.html 就是先加参数,再加# 因为这个页面是有iframe的,所以其实也是传参数到aa.html的,并不是bb.html
具体细看下下列的各对象说明就明白了
location:子对象
document.location.hash // #号后的部分
document.location.host // 域名+端口号
document.location.hostname // 域名
document.location.href // 完整URL
document.location.pathname // 目录部分
document.location.port // 端口号
document.location.protocol // 网络协议(http:)
document.location.search // ?号后的部分

然后到跳转后的页面处理这个地址就可以取到参数值了,方法:

再引用一下http://www.cnblogs.com/kaituorensheng/p/3776527.html内容,说明下#

阅读全文 »

https://www.uedsc.com/xenon.html

Xenon响应式后台管理模板,全套模板,包含后台登录页面、仪表盘、皮肤选择、布局、UI元素、按钮、标签和手风琴、模态、进度条、导航栏、警报、分页、小工具、邮箱、表格、表单、地图、画廊、图标、日历、图像裁切、404错误页、排行榜等共127个后台模板页面。

Xenon HTML模板是一款后台面板 HTML模板。
模板特点:4个仪表盘,28个布局,UI 元素,在线洽谈,时间轴,相册管理,皮肤创建,通告,各种应用元素,提供说明文档等。

阅读全文 »

问题:

  1. 前后端分离
  2. 前端在编写阶段(机器IP:192.168.1.11),后端已经部署好,数据通过REST API提供(机器IP:192.168.1.33:8000/api/)
  3. 跨域问题,就算是端口不一样也会出现。

解决跨域问题有多种,这里选择nginx代理。
####nginx配置

  1. nginx默认监听80端口,由于是编码阶段,我们不改动。

  2. 新建一个server监听8080,并且将http://localhost:8080/api全部转发到http://192.168.1.33:8000/api

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      server {
    listen 8080;
    server_name localhost:8080;

    location / {
    root F:/html/myHtmlTest;
    index index.html index.htm;
    }
    location /api {
    proxy_pass http://192.168.1.33:8000/api;
    }
    }

    或者

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      server {
    listen 8080;
    server_name localhost:8080;

    location / {
    root F:/html/myHtmlTest;
    index index.html index.htm;
    }
    location /api/ {
    proxy_pass http://192.168.1.33:8000;
    }
    }

    两种写法效果一样,区别在于

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    location /api {
    proxy_pass http://192.168.1.33:8000/api;
    }
    #这样写`proxy_pass`不会带上`location`的“/api ”,所以改成这样
    location /test{
    proxy_pass http://192.168.1.33:8000/api;
    }
    #目标访问地址也是不变的
    #但是我们访问就应该是 http://192.168.1.11:8080/test
    #转发到 http://192.168.1.33:8000/api
    1
    2
    3
    4
    5
    6
    location /api/ {
    proxy_pass http://192.168.1.33:8000;
    }
    #这种写法的`proxy_pass`会把`location`的“/api/ ”带上
    #当访问 http://192.168.1.11:8080/api/
    #就会转发为 http://192.168.1.33:8000/api/
  3. 前端html文件(如test.html)放在location /.root的目录下(如F:/html/myHtmlTest)

  4. 通过http://localhost:8080/test.html 访问html文件

  5. ajax访问资源 var url = “http://localhost:8080/api/v1/hello/“;

  6. nginx会将api转发到http://192.168.1.33:8000/api;

Linux下的配置文件include了其他默认的配置,可以在里面配置server,如果不需要可以注释掉。

阅读全文 »

在响应头加入

1
2
3
Access-Control-Allow-Headers →x-requested-with,content-type
Access-Control-Allow-Methods →POST
Access-Control-Allow-Origin →*

表示允许任何域名跨域访问,客户端访问示例 :传送门

环境:Windows10下在WM中安装Linux
错误信息大概如下

1
vcpu-0:VERIFY vmcore/vmm/main/cpuid.c:382 bugNr=1036521

本来vm一直在正常运行,发生这次错误是在电脑(Windows10)的一次不正常关机(断电)之后。

cpu的相关设置记得没有改,vm有些功能是需要电脑开启虚拟cpu技术的(Intel virtual technology),这在装wm的系统时已经开启过了,估计电脑不正常关机导致恢复默认值了。

在BIOS中找到 Intel virtual technology,将其设置为ENABLE就可以了。

阅读全文 »

1
2
3
4
5
6
7
8
9
10
11
12
13
14

<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="你好测试用例啊啊啊啊啊"
android:fontFamily="@font/square_pixel_16"
android:textSize="200sp"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"/>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Test {


public static void main(String[] args) {

System.out.println(Runtime.getRuntime().availableProcessors());
//testSingleThreadExecutor();
//testFixedThreadPool();
//testCachedThreadPool();
}




/**
* 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待
*/
public static void testFixedThreadPool(){
//因为线程池大小为3,每个任务输出index后sleep 2秒,所以每两秒打印3个数字。
//定长线程池的大小最好根据系统资源进行设置。如获取cpu核心数Runtime.getRuntime().availableProcessors()
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
for (int i = 0; i < 10; i++) {
final int index = i;
fixedThreadPool.execute(new Runnable() {
public void run() {
try {
System.out.println(index);
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}


/**
* 创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程。
*/
public static void testCachedThreadPool(){

ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
for (int i = 0; i < 10; i++) {
final int index = i;
try {
Thread.sleep(index * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
cachedThreadPool.execute(new Runnable() {
public void run() {
System.out.println(index);
}
});
}
}


/**
* 创建一个单线程化的线程池,它只会用唯一的工作线程来执行任务,保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行
*/
public static void testSingleThreadExecutor(){
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
for (int i = 0; i < 10; i++) {
final int index = i;
singleThreadExecutor.execute(new Runnable() {
public void run() {
try {
System.out.println(index);
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}

/**
* 创建一个定长线程池,支持定时及周期性任务执行
*/
public static void testScheduledThreadPool(){


ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
scheduledThreadPool.schedule(new Runnable() {
public void run() {
System.out.println("delay 3 seconds");
}
//延迟3秒执行
}, 3, TimeUnit.SECONDS);
//延迟1秒后每3秒执行一次。
//}, 3, TimeUnit.SECONDS);
}
}

Java的内存模型(JMM)规定了所有的变量都是存在于 主内存(RAM) 当中的,而每个线程都有自己的工作内存或者本地内存,线程对变量的所有操作都必须在自己的工作内存中进行,而不能直接对主内存操作,并且每个线程都不能访问其他线程工作内存或者本地内存

比如,在某个线程中对变量 i 的复制操作 i=1,改线程必须在本地内存中对 i 进行修改之后才能将其写入 主内存 之中。

Java内存模型(JMM)三大特性

一、原子性

所有操作都执行或者都不执行

阅读全文 »

1.standard 标准模式

每次启动都new一个实例

2.singleTop 栈顶复用模式(栈顶单例模式)

1
android:launchMode="singleTop"
  • 如果Activity实例处于任务栈栈顶,再启动相同的Activity不会new出一个实例,只会有一个实例。
  • 如果Activity实例存在任务栈不处于栈顶,和standard一样new实例。
阅读全文 »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-122-generic x86_64)

cn@cnserver:~$ sudo apt install snapd
[sudo] password for cn:
Reading package lists... Done
Building dependency tree
Reading state information... Done
snapd is already the newest version (2.47.1+18.04).
snapd set to manually installed.
The following packages were automatically installed and are no longer required:
aufs-tools cgroupfs-mount containerd.io docker-ce-cli libdumbnet1 libltdl7 pigz
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
cn@cnserver:~$
cn@cnserver:~$
cn@cnserver:~$
cn@cnserver:~$ sudo snap install nextcloud
nextcloud 20.0.1snap1 from Nextcloud✓ installed

安装完就启动了,默认端口是80,访问IP:80即可。

Boa是一个只有大概60KB的WebServer,很适合运行在嵌入式硬件设备的Web服务。

在 X86-Ubuntu中安装Boa的日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ wget http://www.boa.org/boa-0.94.14rc21.tar.gz
$ tar zxvf boa-0.94.14rc21.tar.gz
$ cd boa-0.94.14rc21/
$ ls
aclocal.m4 config.guess configure contrib CREDITS examples extras Makefile.in src
CHANGES config.sub configure.in COPYING docs extra_macros.m4 install-sh README
$ ./configure
$ make
$ ls src/
access.c boa.c buffer.o compat.h defines.h get.o index_dir.o Makefile pipe.o range.o response.c signals.o util.c
access.h boa.h cgi.c config.c escape.c globals.h ip.c Makefile.in poll.c read.c response.o sublog.c util.o
alias.c boa_indexer cgi_header.c config.h escape.h hash.c ip.o mmap_cache.c queue.c read.o select.c sublog.o
alias.o boa.o cgi_header.o config.h.in escape.o hash.o log.c mmap_cache.o queue.o request.c select.o timestamp.c
boa buffer.c cgi.o config.o get.c index_dir.c log.o pipe.c range.c request.o signals.c timestamp.o
$ sudo mkdir /etc/boa
$ ls contrib/rpm/
boa.conf boa.init-redhat boa.init-suse boa.logrotate boa.spec
$ sudo cp contrib/rpm/boa.conf /etc/boa
$ sudo ./src/boa
[13/Oct/2020:02:37:06 +0000] No such group: nobody
[13/Oct/2020:02:37:06 +0000] log.c:53 (open_logs) - unable to open error log: No such file or directory
$ sudo mkdir /var/log/boa
$ sudo vim /etc/boa/boa.conf

#修改默认端口
Port 8080
#修改运行身份
User 0
Group 0
#html存放路径
DocumentRoot /www
$ sudo ./src/boa
$ ps -ef|grep boa
root 48727 1 0 11:00 pts/0 00:00:00 ./src/boa
$ netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -