From 08325b1c65979df996ead88c259003e6f2ef3399 Mon Sep 17 00:00:00 2001 From: SCM6WE Date: Wed, 22 Sep 2021 12:57:46 +0200 Subject: [PATCH] Network debugging --- PolyChat/Models/Client.cs | 16 +++++++-- PolyChat/Models/Message.cs | 11 +++++-- PolyChat/Models/NetworkingController.cs | 9 +++--- PolyChat/Package.appxmanifest | 43 ++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/PolyChat/Models/Client.cs b/PolyChat/Models/Client.cs index daf0256..fa79810 100644 --- a/PolyChat/Models/Client.cs +++ b/PolyChat/Models/Client.cs @@ -23,8 +23,15 @@ namespace PolyChat.Models InitEventHandlers(this, connection, uiController); } + /// + /// Called when socket accepts client + /// + /// + /// + /// public Client(SocketIOSocket connection, String ip, MainPage uiController) { + Debug.WriteLine("New Client Saved!!!!(Clinent[34])"); this.ipSelf = ip; this.connection_server = connection; InitEventHandlers(this, connection, uiController); @@ -87,7 +94,9 @@ namespace PolyChat.Models { connection.On(SendCode.Message.ToString(), (Data) => { - Message msg = new Message(Data[0]); + //Message msg = new Message(Data[0]); + Debug.WriteLine("Normal Message Recieved!!!!"); + Message msg = JsonNet.Deserialize(Data[0].ToString()); uiController.OnIncomingMessage(msg); //TODO: send message to GUI @@ -101,6 +110,7 @@ namespace PolyChat.Models connection.On(SocketIOEvent.CONNECTION, () => { + client.connected = true; }); } @@ -114,7 +124,9 @@ namespace PolyChat.Models { connection.On(SendCode.Message.ToString(), (Data) => { - Message msg = new Message(Data[0]); + Debug.WriteLine("Normal Message Recieved!!!!"); + Message msg = JsonNet.Deserialize(Data[0].ToString()); + //Message msg = new Message(Data[0]); uiController.OnIncomingMessage(msg); //TODO: send message to GUI }); diff --git a/PolyChat/Models/Message.cs b/PolyChat/Models/Message.cs index 6e01ea2..3ae2057 100644 --- a/PolyChat/Models/Message.cs +++ b/PolyChat/Models/Message.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Json.Net; +using Newtonsoft.Json.Linq; using System; namespace PolyChat.Models @@ -35,7 +36,8 @@ namespace PolyChat.Models /// public Message(JToken data) { - Message m = (Message) data[0].ToObject(); + + Message m = (Message) data.ToObject(); Sender = m.Sender; Timestamp = m.Timestamp; StringTimeStamp = Timestamp.ToString(); @@ -43,6 +45,11 @@ namespace PolyChat.Models Ip = m.Ip; Foreign = m.Foreign; } + + public Message() + { + + } override diff --git a/PolyChat/Models/NetworkingController.cs b/PolyChat/Models/NetworkingController.cs index d938d50..946dfd4 100644 --- a/PolyChat/Models/NetworkingController.cs +++ b/PolyChat/Models/NetworkingController.cs @@ -11,6 +11,7 @@ using SocketIOSharp.Server; using SocketIOSharp.Server.Client; using Newtonsoft.Json.Linq; using System.Threading; +using Json.Net; namespace PolyChat.Models { @@ -53,9 +54,9 @@ namespace PolyChat.Models { socket.On(SendCode.Initial.ToString(), (JToken[] Data) => { - Debug.WriteLine("Client connected!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - Message m = new Message(Data[0]); - clients.Add(new Client(socket,m.Ip, uiController)); + Debug.WriteLine("Client connected and Initial Message Recieved!!!!!!!!!!!!!!!!!"); + Message msg = JsonNet.Deserialize(Data[0].ToString()); + clients.Add(new Client(socket,msg.Ip, uiController)); }); } @@ -66,7 +67,7 @@ namespace PolyChat.Models /// to send public void sendMessage(String ip, String msg) { - this.getClient(ip).sendMessage(SendCode.Initial, msg); + this.getClient(ip).sendMessage(SendCode.Message, msg); } /// diff --git a/PolyChat/Package.appxmanifest b/PolyChat/Package.appxmanifest index d4a461b..3d5e5b6 100644 --- a/PolyChat/Package.appxmanifest +++ b/PolyChat/Package.appxmanifest @@ -4,7 +4,12 @@ xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" - IgnorableNamespaces="uap mp"> + xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" + xmlns:uap6="http://schemas.microsoft.com/appx/manifest/uap/windows10/6" + xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" + xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4" + xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" + IgnorableNamespaces="uap mp uap3 uap6 iot uap4 uap2"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file