分类 技术专栏 下的文章

以本地链接线上websocket为例,如图所示
var ws = new WebSocket("ws://127.0.0.1:6543");
ws.onopen = function()
{
ws.send(JSON.stringify({'type':'bind','uid':1}))
};
步骤一:如果请求域名为http,则可以正常访问,然而当域名为https时,就会报错,如下图所示

img_a2f013e1901998dcd0bc3adc61ec82ec.png

错误信息:Mixed Content: The page at ‘https://{域名}.com/‘ was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint ‘ws://{ip}:{port}/‘. This request has been blocked; this endpoint must be available over WSS.
Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS

步骤二:根据错误提示信息,需要使用wss请求var ws = new WebSocket("wss://127.0.0.1:6543");

这时重新访问,会出现如下图所示信息
错误信息:failed:Error in connection establishment: newt::ERR_SSLPROTOCOL_ERROR
注:在使用https协议时,需要指定域名,这里换成ws = new WebSocket("wss://{域名}/wss");
同时修改nginx配置文件,在conf中加入以下代码
location /wss {
proxy_pass http://172.30.9.176:6543;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

}
重启nginx服务后即可正常通讯

今天面试遇到一个奇葩问题,让写出int类型的长度范围,数字那么大,瞬间懵逼,特此来总结一下,方便记忆
我们知道int类型占4个字节,1字节是bit,计算机存储单位是位,但是在2进制中,0001 = 1 = 2^1-1, 0011 = 3 = 2^2-1 ...,以此类推,计算结果=2^n次方-1,所以最大值 0111 1111 1111 1111 1111 1111 1111 1111 = 2^(32-1)-1 (这里再减去1是因为最高位32位标志位,不参与运算),最小值为-2^(32-1)-1,然后说一下中间值0,根据符号位的不同,有+0和-0的区别
+0: 00000000 00000000 00000000 00000000
-0: 10000000 00000000 00000000 00000000
由于0只能使用一个,本着不浪费的原则,用+0表示0,那-0就可以在最小的基础上再表示一个数值,所以对于有符号型,最小值可以是-(2^(32-1)-1)+1,所以int类型有符号型表示的范围就-2^到2^(32-1)-1

对应其他几种数据类型
tinyint 占1字节
smallint 占2字节
mediumint 占3字节
bigint 占8字节

参考:https://blog.csdn.net/weixin_43401380/article/details/121199473

生成桌面快捷方式程序如下

  header("Content-type: text/html; charset=gbk");
  $title = !empty($_GET['title'])?$_GET['title']:'';//获取传值
  $url = !empty($_GET['url'])?$_GET['url']:'';//获取传值

  $title = test_input($title);
  $url = test_input($url);

  $Shortcut = "[InternetShortcut]
  URL=".$url."
  IDList=
  [{000214A0-0000-0000-C000-000000000046}]
  Prop3=19,2
  ";
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename=".$title.".url;");
  echo $Shortcut;

备注:页面编码必须为gbk或gb2312