Websocket Server

A few illustrated reminds about simple static http server.
For complete explanations, please have a look at : https://web.enib.fr/~harrouet


Considering that in HTTP, the value can change only after a client request,
if I want to refresh a value on a web page, I can :

  • download all the page ( heavy php way )
  • Make the client ask to refresh a value ( javascript / ajax way )
  • change the http protocole in a websocket protocole to get a bidirectionnal communication tube between the client and the server.

Websocket Server ( server sends random datas )

code_ws_rand.zip

ws_1.svg

ws_2.svg

ws_3.svg

ws_4.svg

ws_5.svg

ws_6.svg

ws_7.svg

ws_8.svg

httpDynServerWs.c
Le fichier iot/linux-server-programming/websocket-server/code_ws_rand/httpDynServerWs.c n'a pas été trouvé à l'emplacement spécifié.
# RPI Terminal

$ ./exec_httpDynServerWs 5555
new HTTP connection from 192.168.0.1:44086
GET / HTTP/1.1
Host: 192.168.0.2:5555
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1

new HTTP connection from 192.168.0.1:44092
GET /favicon.ico HTTP/1.1
Host: 192.168.0.2:5555
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: */*
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive

# click on 'websocket appli' link :

new HTTP connection from 192.168.0.1:44096
GET /wsAppli.html HTTP/1.1
Host: 192.168.0.2:5555
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://192.168.0.2:5555/
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1

new HTTP connection from 192.168.0.1:44098
GET / HTTP/1.1
Host: 192.168.0.2:5555
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://192.168.0.2:5555
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: H3eb/3onA9ZjQavD3M4MXA==
DNT: 1
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

upgrading to websocket