Program.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using Fleck;
  4. using FingerprintScanner;
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. var allSockets = new List<IWebSocketConnection>();
  10. var server = new WebSocketServer("ws://0.0.0.0:5000");
  11. // Start WebSocket server
  12. server.Start(socket =>
  13. {
  14. socket.OnOpen = () =>
  15. {
  16. Console.WriteLine("Client connected!");
  17. allSockets.Add(socket);
  18. };
  19. socket.OnClose = () =>
  20. {
  21. Console.WriteLine("Client disconnected!");
  22. allSockets.Remove(socket);
  23. };
  24. socket.OnMessage = message =>
  25. {
  26. Console.WriteLine("Received: " + message);
  27. // You can handle incoming messages here if needed
  28. };
  29. socket.OnError = error =>
  30. {
  31. Console.WriteLine("Error: " + error.Message);
  32. };
  33. });
  34. var fingerprintManager = new FingerprintCaptureManager();
  35. // Subscribe to fingerprint captured event and broadcast to all clients
  36. fingerprintManager.OnFingerprintCaptured += (jsonData) =>
  37. {
  38. Console.WriteLine("Broadcasting fingerprint data...");
  39. foreach (var socket in allSockets)
  40. {
  41. socket.Send(jsonData);
  42. }
  43. };
  44. // Pass the targetVid string here. Replace with your actual VID if known.
  45. fingerprintManager.Start();
  46. Console.WriteLine("Fingerprint WebSocket server running on ws://0.0.0.0:5000/");
  47. Console.WriteLine("Press Enter to stop...");
  48. Console.ReadLine();
  49. fingerprintManager.Stop();
  50. }
  51. }