HttpServerBoxed 0.0.11 alpha
A simple http server for C# and .NET
Loading...
Searching...
No Matches
Runner.Servlets Namespace Reference

Functions

class BulkWSPage (Request req, Response res)
 
class BulkWebSocket (Request req, Response res, Configuration c)
 

Function Documentation

◆ BulkWebSocket()

class Runner.Servlets.BulkWebSocket ( Request  req,
Response  res,
Configuration  c 
)

Definition at line 58 of file BulkWebSocket.cs.

58 : WebSocket(req, res, c)
59{
60
61 public override void OnOpen()
62 {
63 Console.WriteLine("opened");
64 }
65
66 public override void OnMessage(Message message)
67 {
68 Console.WriteLine(message.GetMessage());
69 }
70
71 public override void OnClose()
72 {
73 Console.WriteLine("closed");
74 }
75}
class WebSocket(Request req, Response res, Configuration? c=null)
Definition WebSocket.cs:11

◆ BulkWSPage()

class Runner.Servlets.BulkWSPage ( Request  req,
Response  res 
)

Definition at line 9 of file BulkWebSocket.cs.

9 : Servlet(req, res)
10{
11
12 public override void ProcessGet()
13 {
14 //returns and html page that spawns 20 websockets connections
15 //and send a message to the server every 2 seconds
16 var html = @"<html>
17 <head>
18 <script>
19 var ws = [];
20 for(let i = 0; i < 20; i++){
21 let wsx = new WebSocket('ws://localhost:8080/ws_bulk');
22 wsx.onopen = function(){
23 console.log('opened');
24 }
25 wsx.onmessage = function(e){
26 console.log(e.data);
27 }
28 wsx.onclose = function(){
29 console.log('closed');
30 }
31
32 setTimeout(function(){
33 setInterval(function(){
34 if(wsx.readyState == 1){
35 console.log('sending message from : ' + i)
36 wsx.send('hello from ' + i );
37 }
38 }, 100 * i);
39
40 }, 100 * i);
41
42 ws.push(wsx);
43 }
44
45
46 </script>
47 </head>
48 <body>
49 <h1>Websocket Test</h1>
50 </body>
51 </html>";
52 res.SendHTMLContent(html);
53 }
54}
void SendHTMLContent(string content, bool process=false, int statusCode=HTTP_CODES.OK, string encoding="UTF-8", Dictionary< string, string >? customHeaders=null)
Sends an html page passed as string.
Definition Response.cs:110