node-js-socket-io-with-ssl:
https://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl?noredirect=1&lq=1
ref: https://socket.io/get-started/chat/
#### basic nodejs app:
express
to html as client end.package.json
manifest file that describes our projectnpm install express@4.15.2
index.js
file that will setup our applicationindex.js
file supply the html content of "Hello world".index.html
file and modify the index.js
to serve the index.html
.#### Insert socket.io:
The socket.io
has a service end (socket.io) and client end (socket.io-client).
npm install socket.io
index.js
, initialize a new instance of socket.io
by passing the http
(the HTTP server) object.connection
event for incoming sockets, and I log it to the console.index.html
, add the snippet about var socket = io();
for loading the socket.io-client.#### Emitting events:
Send and receive any events we want, with any data. Any objects that can be encoded as JSON will do, and binary data is supported too.
index.html
.index.js
we print out the chat message event#### Broadcasting:
io.emit(‘chat message‘, msg);
chat message
event: socket.on(‘chat message‘, function(msg){ ...
For more details: https://socket.io/get-started/chat/
Even though the Caddy is the convenient server for https and the certificate application. The nginx is still the wider used solution for web service.
原文:https://www.cnblogs.com/sonictl/p/12533172.html