JS binary auth

var Auth = {
  auth : 0,
  
  init : function(auth) {
   this.auth = auth;
   return this;
  },
  
  addAuth : function(auth){
   this.auth = this.auth | parseInt(auth);
   return this.auth;
  },
  
  isAuth : function(auth){
   if ( (this.auth & parseInt(auth)) == 0){
    return false;
   }
   return true;
  },
  
  delAuth : function(auth){
   this.auth = this.auth & ~parseInt(auth);
   return this.auth;
  }
 }
 
 
 var oAuth = Auth.init(1);
 console.log("init auth:\n " + oAuth.auth);
 oAuth.addAuth(2);
 console.log("add auth:\n" + oAuth.auth);
 console.log("is auth: \n" + oAuth.isAuth(2));
 
 oAuth.addAuth(4);
 console.log("add auth:\n" + oAuth.auth);
 
 //oAuth.delAuth(2);
 //console.log("add auth:\n" + oAuth.auth); 
 console.log("is auth: \n" + oAuth.isAuth(8));
WebSockets are a communication protocol that allows two-way communication between a client and a server over a single, long-lived connection. While WebSockets are typically used for text-based communication, they can also be used to send binary data. To send binary data over a WebSocket, you first need to convert the data to a binary format. This can be done using the ArrayBuffer or Blob APIs in JavaScript. Once you have the binary data, you can send it over the WebSocket using the send() method. Here's an example of sending binary data over a WebSocket using the ArrayBuffer API: ``` // create a WebSocket connection const ws = new WebSocket('wss://example.com'); // create binary data const buffer = new ArrayBuffer(4); const view = new DataView(buffer); view.setUint32(0, 1234); // send binary data over WebSocket ws.send(buffer); ``` In this example, we create a new WebSocket connection to "wss://example.com". We then create a new ArrayBuffer with a length of 4 bytes and set the value to 1234 using the DataView API. Finally, we send the binary data over the WebSocket using the send() method. Note that you can also use the Blob API to send binary data over a WebSocket. The process is similar to using the ArrayBuffer API, but instead of creating an ArrayBuffer, you create a Blob object and pass it to the send() method. ``` // create a WebSocket connection const ws = new WebSocket('wss://example.com'); // create binary data const blob = new Blob(['Hello, world!'], { type: 'text/plain' }); // send binary data over WebSocket ws.send(blob); ``` In this example, we create a new WebSocket connection to "wss://example.com". We then create a new Blob object with the text "Hello, world!" and a MIME type of "text/plain". Finally, we send the binary data over the WebSocket using the send() method.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值