OLD | NEW |
1 <!DOCTYPE html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>test ws connection</title> | 4 <title>Connect to a WebSocket server</title> |
5 <script type="text/javascript"> | 5 <script type="text/javascript"> |
6 | 6 |
| 7 |
7 var href = window.location.href; | 8 var href = window.location.href; |
8 var hostBegin = href.indexOf('/') + 2; | 9 var hostBegin = href.indexOf('/') + 2; |
9 var hostEnd = href.lastIndexOf(':'); | 10 var hostEnd = href.lastIndexOf(':'); |
10 var host = href.slice(hostBegin, hostEnd); | 11 var host = href.slice(hostBegin, hostEnd); |
11 var portBegin = hostEnd + 1; | 12 var portBegin = hostEnd + 1; |
12 var portEnd = href.lastIndexOf('/'); | 13 var portEnd = href.lastIndexOf('/'); |
13 var port = href.slice(portBegin, portEnd); | 14 var port = href.slice(portBegin, portEnd); |
14 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; | 15 var scheme = href.indexOf('https') >= 0 ? 'wss' : 'ws'; |
15 var url = scheme + '://' + host + ':' + port + '/echo-with-no-extension'; | 16 var url = scheme + '://' + host + ':' + port + '/count-connection'; |
16 | 17 |
17 // Do connection test. | 18 // Do connection test. |
18 var ws = new WebSocket(url); | 19 var ws = new WebSocket(url); |
19 | 20 |
20 ws.onopen = function() | 21 ws.onmessage = function(e) { |
21 { | 22 document.title = (e.data === 'open: 1, closed: 1' ? 'PASS' : 'FAIL'); |
22 // Set document title to 'PASS'. The test observer catches this title changes | |
23 // to know the result. | |
24 document.title = 'PASS'; | |
25 } | 23 } |
26 | 24 |
27 ws.onclose = function() | 25 ws.onclose = function() { |
28 { | 26 document.title = 'FAIL'; |
29 // Set document title to 'FAIL'. | 27 }; |
30 document.title = 'FAIL'; | |
31 } | |
32 | 28 |
33 </script> | 29 </script> |
34 </head> | 30 </head> |
35 </html> | 31 </html> |
OLD | NEW |