mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:22:43 +00:00 
			
		
		
		
	 22413ef729
			
		
	
	
		22413ef729
		
	
	
	
	
		
			
			The WebSocket bindings match the original specification from the WHATWG living standard, but do not match the later update of the standard that involves FETCH. The FETCH update will be handled later since the changes would also affect XMLHttpRequest.
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE html>
 | |
| <html>
 | |
|     <head>
 | |
|         <meta charset="utf-8" />
 | |
|         <title>WebSocket Test</title>
 | |
|     </head>
 | |
|     <body>
 | |
|         <h2>WebSocket Test</h2>
 | |
|         <div id="output"></div>
 | |
|         <script type="text/javascript">
 | |
|             var output = document.getElementById('output');
 | |
| 
 | |
|             function println(message) {
 | |
|                 const p = document.createElement('p');
 | |
|                 p.innerHTML = message;
 | |
|                 output.appendChild(p);
 | |
|             }
 | |
| 
 | |
|             // Websocket echo server, provided from https://www.websocket.org/echo.html
 | |
|             var targetUrl = 'wss://echo.websocket.org';
 | |
|             var messageContent = 'Hello friends :^)';
 | |
|             println('<span style="color: blue;">Connecting to:</span> ' + targetUrl);
 | |
|             websocket = new WebSocket(targetUrl);
 | |
|             websocket.onopen = function() {
 | |
|                 println('<span style="color: green;">Connected to:</span> ' + targetUrl);
 | |
|                 println('<span style="color: blue;">Sending Message:</span> ' + messageContent);
 | |
|                 websocket.send(messageContent);
 | |
|             };
 | |
|             websocket.onmessage = function(event) {
 | |
|                 println('<span style="color: green;">Received Response:</span> ' + event.data);
 | |
|                 println('<span style="color: blue;">Closing connection...</span> ');
 | |
|                 websocket.close();
 | |
|             };
 | |
|             websocket.onerror = function(evt) {
 | |
|                 println('<span style="color: red;">ERROR:</span> ' + evt.data);
 | |
|             };
 | |
|             websocket.onclose = function() {
 | |
|                 println('<span style="color: green;">Connection closed!</span>');
 | |
|             };
 | |
|           </script>
 | |
|     </body>
 | |
| </html>
 |