Websocket_server

所属分类:网络编程
开发工具:C/C++
文件大小:44KB
下载次数:9
上传日期:2019-07-01 21:50:01
上 传 者wynnfay
说明:  websocket服务端代码,可以帮助初学者了解websocket原理,包括如何握手,加密等
(Websocket server code, can help beginners understand the principles of websocket, including how to shake hands, encryption, etc.)

文件列表:
Communicate.c (15541, 2017-06-28)
Communicate.h (1476, 2017-06-28)
Datastructures.c (10789, 2017-06-28)
Datastructures.h (3722, 2017-06-28)
Errors.c (3304, 2017-06-28)
Errors.h (1564, 2017-06-28)
Handshake.c (21258, 2017-06-28)
Handshake.h (2795, 2017-06-28)
Hosts.dat (37, 2017-06-28)
Includes.h (2438, 2017-06-28)
LICENSE (1101, 2017-06-28)
Makefile (969, 2017-06-28)
Origins.dat (81, 2017-06-28)
Websocket.c (16021, 2017-06-28)
base64.c (12727, 2017-06-28)
base64.h (1563, 2017-06-28)
md5.c (9648, 2017-06-28)
md5.h (2984, 2017-06-28)
sha1.c (10382, 2017-06-28)
sha1.h (1574, 2017-06-28)
utf8.c (5453, 2017-06-28)
utf8.h (1102, 2017-06-28)

# Websocket Server in C The code in this repository is supposed to support the awesome websocket feature, that was introduced as part of the HTML5 standard. The idea with the project was originally to learn the C language and furthermore understand the basics of websockets. # Support The websocket server is written in C and should be supported by the most UNIX systems. It does not have any dependencies to other libraries than the standard libraries in UNIX. As of 09/04-2013 it has been compiled and tested on the following operating systems: * Ubuntu 12.04 * Arch Linux * MAC OS x 10.8 BEWARE! It does not work in Windows! # Conventions As websockets is a pretty new feature, there has been a lot of different conventions on how to handle the communication between browser and server. This websocket server should support the following conventions: * [hixie-75](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75) which was supported by Chrome 4 and Safari 5.0.0 and forth. (NOT TESTED and/or IMPLEMENTED) * [hixie-76](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76) which was supported by Firefox 4, Chrome 6, Safari 5.0.1 and Opera 11 and forth. * [hybi-07](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07) which was supported by Firefox 6 and forth. * [hybi-10](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10) which was supported by Firefox 7, Chrome 14 and forth. * [RFC***55](http://tools.ietf.org/html/rfc***55) which was supported by IE 10, Firefox 11, Chrome 16, Safari 6 and Opera 12.10 and forth. The latter RFC***55 is the convention that is supposed to be the standard for websockets according to the HTML5 standards. # How to use With the C code follows a makefile. This is used to compile and run the code. What you do is simply open your terminal and navigate to the root folder of the websocket server. To compile the code, simply type: `make` To run the websocket server type: `make run` To run the websocket server with valgrind (requires that valgrind is installed) type: `make valgrind` The default port of the server is currently port 4567. If you wish to have another port you can simply type: `make run PORT=1111` which will make the server listen at port 1111. When the server is up and running, it has a few commands that could be useful. These commands can be displayed by typing `help`. Last but not at least, it is up to the one running the server to decide which hosts and origins that is allowed. To choose these addresses, you can edit the 2 files `Hosts.dat` and `Origins.dat`. The first line in the file indicates the amount of addresses allowed, and the following lines is the actual addresses allowed. `Hosts.dat` has the information:
2
localhost
127.0.0.1
`Origins.dat` has the information:
2
http://localhost
http://127.0.0.1
As some of the conventions does not require the client to set an origin, I have choosen to implement it as follows. If the client supplies an origin, then we check if the origin is listed in `Origins.dat`. If the origin was not supplied, 2 things can happen. In `Includes.h` a constant "ORIGIN\_REQUIRED" has been made, which defines which one of the two options to choose. If this constant is 0, we accept the fact that we can't check the origin from the client and just moves on. If it is not 0, then we close the connection to the client, as he was not able to identify where he originated from. # Future implementations In the future, the server should be able to communicate with browsers, eventhough the browser is just trying to contact the server using a normal HTTP Request. The idea is to implement some kind of COMET server, such that the server is useful for old browsers as well. Another thing that would be preferable is that the server is able to handle SSL connections. Which includes being able to handle wss:// connections. This implementation would probably require that "OPENSSL" is installed on the computer, as it would be too much work to implement my own version of SSL. Finally me and my pal is currently developing a benchmark tool for a websocket server, such that we can find bugs in the server and benchmark how much it can do. The project can be seen [here](https://github.com/hovmand/go-websocket-bench) .

近期下载者

相关文件


收藏者