Skip to content
Snippets Groups Projects

Web socket server

1 file
+ 28
1
Compare changes
  • Side-by-side
  • Inline
using InnoLabProjektDektopApp.Services;
using InnoLabProjektDektopApp.Services.WebSocketServer;
using System.IO;
using System.Net.Sockets;
using System.Text.Json;
@@ -266,6 +267,34 @@ namespace InnoLabProjektDektopApp
// Ereignis-Handler für den "Start"-Button
private void StartButton_Click(object sender, RoutedEventArgs e)
{
Server.Instance.SendMessageToAllClients("{\"action\": \"startTracking\", \"status\": true}");
try
{
string jsonContent = File.ReadAllText("F:\\Dokumente\\Schule\\Studium\\InoLab\\procrastinator\\InnoLabProjektDektopApp\\InnoLabProjektDektopApp\\Assets\\distractingWebsites.json");
//string message = $"{{\"action\": \"sendJsonContent\", \"status\": true, \"content\": {jsonContent}}}";
// Erstelle ein Objekt für die Nachricht
var messageObject = new
{
action = "sendJsonContent",
status = true,
content = JsonSerializer.Deserialize<object>(jsonContent) // Parse den JSON-Inhalt
};
// Serialisiere das Objekt zu einem JSON-String
string message = JsonSerializer.Serialize(messageObject);
Server.Instance.SendMessageToAllClients(message);
}
catch
{
}
// Werte auslesen
int focusPeriod;
Loading