added switch for incoming network data

This commit is contained in:
Sem van der Hoeven
2020-10-13 10:23:06 +02:00
parent 66efaf736d
commit 514460781b
6 changed files with 30 additions and 4 deletions

View File

@@ -4,6 +4,7 @@ namespace Server.Models
{
public class Information : ObservableObject
{
public bool CanStartServer { get; set; }
public bool ServerOnline { get; set; }
@@ -15,5 +16,7 @@ namespace Server.Models
return "Offline";
}
}
public int ClientsConnected{ get; set; }
}
}

View File

@@ -84,7 +84,23 @@ namespace Server.Models
/// <param name="message">the incoming message</param>
private void HandleIncomingMessage(byte[] message)
{
Debug.WriteLine($"Got message from client : {message}");
Debug.WriteLine($"Got message from {Username} : {message}");
byte id = message[0];
switch(id)
{
case 0x01:
// canvas data
break;
case 0x02:
// message data
break;
case 0x03:
// json data
break;
default:
Debug.WriteLine("Received weird identifier: " + id);
break;
}
//TODO implement ways to handle the message
}

View File

@@ -9,6 +9,7 @@ using System.Net.Sockets;
using System.Text;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Server.ViewModels
{
@@ -24,8 +25,11 @@ namespace Server.ViewModels
this.mainWindow = mainWindow;
Debug.WriteLine("init mainviewmodel");
InformationModel = new Information();
InformationModel.ClientsConnected = 0;
InformationModel.CanStartServer = true;
InformationModel.ServerOnline = false;
//BitmapImage onlineImg = new BitmapImage(new Uri(@"/img/online.png",UriKind.Relative));
//BitmapImage offlineImg = new BitmapImage(new Uri(@"/img/offline.png", UriKind.Relative));
this.ServerStartCommand = new RelayCommand(() =>
{
@@ -38,7 +42,7 @@ namespace Server.ViewModels
if (!serverCommunication.Started)
{
Debug.WriteLine("can start server " + InformationModel.CanStartServer);
serverCommunication.Start();
InformationModel.ServerOnline = true;
InformationModel.CanStartServer = false;

View File

@@ -8,8 +8,11 @@
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Start Server" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Command="{Binding ServerStartCommand}" IsEnabled="{Binding InformationModel.CanStartServer}"/>
<Label Name="serverStatusLabel" Content="{Binding InformationModel.ServerStatus}" HorizontalAlignment="Left" Margin="169,10,0,0" VerticalAlignment="Top"/>
<Label Name="serverStatusLabel" Content="{Binding InformationModel.ServerStatus}" HorizontalAlignment="Left" Margin="174,7,0,0" VerticalAlignment="Top"/>
<Label Content="Server Status:" HorizontalAlignment="Left" Margin="80,7,0,0" VerticalAlignment="Top"/>
<Image Source="https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/16/Status-user-online-icon.png" HorizontalAlignment="Left" Margin="161,16,0,0" VerticalAlignment="Top" Width="8"/>
<Label Content="Clients connected:" HorizontalAlignment="Left" Margin="10,35,0,0" VerticalAlignment="Top"/>
<Label Content="{Binding InformationModel.ClientsConnected}" HorizontalAlignment="Left" Margin="117,35,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>

BIN
Server/img/offline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 B

BIN
Server/img/online.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B