Fixed json formatting in SendMessage

This commit is contained in:
Patrick Hellebrand
2021-09-22 15:50:19 +02:00
parent ee7af3c984
commit 957644b841

View File

@@ -6,6 +6,7 @@ using SocketIOSharp.Server;
using SocketIOSharp.Server.Client; using SocketIOSharp.Server.Client;
using PolyChat.Models; using PolyChat.Models;
using System.Text.Json; using System.Text.Json;
using Newtonsoft.Json;
namespace PolyChat namespace PolyChat
{ {
@@ -43,7 +44,7 @@ namespace PolyChat
private void Serve() private void Serve()
{ {
Debug.WriteLine("! SERVER STARTING !"); Debug.WriteLine("--- Controller.Serve ---");
SocketIOServer server = new SocketIOServer(new SocketIOServerOption( SocketIOServer server = new SocketIOServer(new SocketIOServerOption(
PORT PORT
)); ));
@@ -70,9 +71,12 @@ namespace PolyChat
{ {
Debug.WriteLine("--- Controller.SendMessage ---"); Debug.WriteLine("--- Controller.SendMessage ---");
Debug.WriteLine($"{type} -> {ip} content: {content}"); Debug.WriteLine($"{type} -> {ip} content: {content}");
string json = $"{{ type: {type}, content: {content} }}"; JObject json = new JObject(
Debug.WriteLine($"json: {json}"); new JProperty("type", type),
Connections[ip].SendMessage(json); new JProperty("content", content)
);
Debug.WriteLine($"json: {json.ToString()}");
Connections[ip].SendMessage(json.ToString());
} }
private void OnMessage(string ip, JToken[] data) private void OnMessage(string ip, JToken[] data)