-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (71 loc) · 2.35 KB
/
Program.cs
File metadata and controls
77 lines (71 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Filename: Program.cs
* Author: Alessio Carello
* Last Update: 20/10/2018 12.09.14
*/
namespace WebSocketServer
{
using System;
using System.Collections.Generic;
using System.Threading;
/// <summary>
/// Defines the <see cref="Program" />
/// </summary>
internal class Program
{
/// <summary>
/// The Main
/// </summary>
/// <param name="args">The args<see cref="string[]"/></param>
internal static void Main(string[] args)
{
m_registeredClient = new HashSet<Guid>();
WebSocketServer.Istance.RegisterAsyncHandler("GetVuMeterValues", sendData);
WebSocketServer.Istance.RegisterHandler("StopSendVuMeterValues", stopSendData);
WebSocketServer.Istance.Start().Wait();
}
/// <summary>
/// Defines the m_registeredClient
/// </summary>
private static HashSet<Guid> m_registeredClient;
/// <summary>
/// The stopSendData
/// </summary>
/// <param name="client">The client<see cref="WebSocketClient"/></param>
/// <param name="arg">The arg<see cref="string"/></param>
/// <returns>The <see cref="string"/></returns>
private static string stopSendData(WebSocketClient client, string arg)
{
if (!m_registeredClient.Contains(client.Id))
{
#if FULL_LOG
Console.WriteLine($"Client {client.Id} has never registered");
#endif
return string.Empty;
}
m_registeredClient.Remove(client.Id);
return string.Empty;
}
/// <summary>
/// The sendData
/// </summary>
/// <param name="client">The client<see cref="WebSocketClient"/></param>
internal static void sendData(WebSocketClient client)
{
if (m_registeredClient.Contains(client.Id))
{
#if FULL_LOG
Console.WriteLine($"Client {client.Id} already registered");
#endif
return;
}
var rng = new Random();
m_registeredClient.Add(client.Id);
while (m_registeredClient.Contains(client.Id))
{
if (!WebSocketServer.Istance.Write(client, rng.Next(1, 100).ToString())) { return; }
Thread.Sleep(1000 / 15);
}
}
}
}