windows平台上实现websocket服务器

windows平台上实现websocket服务器

目前做个项目需要做个带串口的测试软件,主要功能是一台电脑利用串口控制一台待测试设备,然后通过串口对他进行调试,同时使用串口采集其他测量设备的数值,将测试过程的数据保存进数据库,及实时的曲线等显示。由于需要同时进行一些文档处理,且操作人员习惯个windows。
这样一个需求最正统的方案肯定是使用VC做开发。但是VC做UI,显示图标啥的,涉及太深的api,实在没心情研究,于是想了个自认为奇葩的办法,就是使用浏览器做UI,然后用c开发一个控制台程序,做一个websocket服务器。web做简单的UI入门相对简单。目前浏览器都支持html5,然后开个全屏发现效果还不错基本和VC的UI可以以假乱真。
C开发websocket时碰到问题,websocket内需要SHA1算法,如果使用openssl的库,说实话,做个库对win平台不太友好,还好网上有大神贴出来的单独的函数。
做websocket服务器主要有以下几点原理需要明确:
A、websocket和普通的TCP的区别:
1、在于它每次传输的时候都加了一个头。
2、它有一个握手协议,做个里面有个SHA1和base64的算法。如果可以的话建议在linux平台做。
3、它的头里面包含一个使用ascii还是bit传输的标志,如果需要大数据,明显bit传输合适,使用JavaScript的相关函数就 能解析了。
B、UI主要需要使用到JavaScript,HTML5.如果需要数据库的话就使用php。搭建平台我是安装了wampserver3.1.0_x86,全部搞定。

实践下来性能完全够用,每5秒存一次数据库,能够正常显示曲线数据。还有个优点是,我有4台测试电脑,web服务器之转一台,这样都不用和以前一样将excel文档传来传去了。
希望这个方案能给大家一点建议 。
C语言写的websocket服务器,同时操作串口

HTML 5 Web Sockets is a powerful and effective technique for real-time information processing. There exists many techniques such as Poling, Long Poling and Streaming that are said to be better earier days. With web sockets, it shows a better outcome for the end user as well as a proper utilization of the server bandwidth. WebSocket is a web technology providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API for in Web IDL is being standardized by the W3C.WebSocket is designed to be implemented in web browsers and web servers, but it can be used by any client or server application. The WebSocket Protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. The WebSocket protocol makes possible more interaction between a browser and a web site, facilitating live content and the creation of real-time games. This is made possible by providing a standardized way for the server to send content to the browser without being solicited by the client, and allowing for messages to be passed back and forth while keeping the connection open. In this way a two-way (bi-directional) ongoing conversation can take place between a browser and the server. A similar effect has been achieved in non-standardized ways using stop-gap technologies such as Comet.In addition, the communications are done over TCP port number 80, which is of benefit for those environments which block non-standard Internet connections using a firewall. WebSocket protocol is currently supported in several browsers including Google Chrome, Internet Explorer, Firefox, Safari and Opera. WebSocket also requires web applications on the server to support it. Here goes a comparison of polling vs Web Sockets.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值