ActiveX(五)更好的“ActiveX”?

  前文中四篇随笔、已经可以实现 ActiveX 与 Js 无缝交互、 也就是说借用ActiveX实现更加强大的功能已经完全不是问题。但是、ActiveX 本身还有一个局限性——浏览器兼容问题。如此强大的ActiveX却因为浏览器兼容而饱受折磨,是不是有些可惜?

  那有没有更好的方式可以代替ActiveX呢?

  如果、我们使用.NET开发一独立的Application(WinForm 、Web、 或者 Windows服务)、并在客户端部署,并使用Js进行跨进程通讯,该方案是否可运行呢?然而、恰好,WebSocket走进了我的视野,借用强大的WebSocket、我们可以轻易地实现跨进程通讯。接下来的几篇随笔、我将验证采用该方案去替代ActiveX的可行性。

WebSocket介绍

  下面有几篇文章是介绍WebSocket的,分享一下:

      Socket 与 WebSocket

  WebSocket(2)--为什么引入WebSocket协议

  WebSocket(1)-- WebSocket API简介

  WebSocket(4)-- WebSocket与TCP、Http的关系

  OSI七层模型详解

网络协议图.zip (原图)

 

关于如何应用WebSocket

     1、.NET 中使用 WebSocket

  • Server - HttpListener
  • Client - ClientWebSocket

  2、Js 中使用 WebSocket (详见:WebSocket(1)-- WebSocket API简介)  

var ws = new WebSocket(“ws://echo.websocket.org”);

ws.onopen = function(){ws.send(“Test!”); };

ws.onmessage = function(evt){console.log(evt.data);ws.close();};

ws.onclose = function(evt){console.log(“WebSocketClosed!”);};

ws.onerror = function(evt){console.log(“WebSocketError!”);};

 

  (未完待续...)

 

posted @ 2016-02-22 19:00  把爱延续  阅读(1595)  评论(0编辑  收藏  举报