added switch for incoming network data
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Server.Models
|
|||||||
{
|
{
|
||||||
public class Information : ObservableObject
|
public class Information : ObservableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
public bool CanStartServer { get; set; }
|
public bool CanStartServer { get; set; }
|
||||||
public bool ServerOnline { get; set; }
|
public bool ServerOnline { get; set; }
|
||||||
|
|
||||||
@@ -15,5 +16,7 @@ namespace Server.Models
|
|||||||
return "Offline";
|
return "Offline";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int ClientsConnected{ get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,23 @@ namespace Server.Models
|
|||||||
/// <param name="message">the incoming message</param>
|
/// <param name="message">the incoming message</param>
|
||||||
private void HandleIncomingMessage(byte[] message)
|
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
|
//TODO implement ways to handle the message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Net.Sockets;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace Server.ViewModels
|
namespace Server.ViewModels
|
||||||
{
|
{
|
||||||
@@ -24,8 +25,11 @@ namespace Server.ViewModels
|
|||||||
this.mainWindow = mainWindow;
|
this.mainWindow = mainWindow;
|
||||||
Debug.WriteLine("init mainviewmodel");
|
Debug.WriteLine("init mainviewmodel");
|
||||||
InformationModel = new Information();
|
InformationModel = new Information();
|
||||||
|
InformationModel.ClientsConnected = 0;
|
||||||
InformationModel.CanStartServer = true;
|
InformationModel.CanStartServer = true;
|
||||||
InformationModel.ServerOnline = false;
|
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(() =>
|
this.ServerStartCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
@@ -38,7 +42,7 @@ namespace Server.ViewModels
|
|||||||
if (!serverCommunication.Started)
|
if (!serverCommunication.Started)
|
||||||
{
|
{
|
||||||
|
|
||||||
Debug.WriteLine("can start server " + InformationModel.CanStartServer);
|
|
||||||
serverCommunication.Start();
|
serverCommunication.Start();
|
||||||
InformationModel.ServerOnline = true;
|
InformationModel.ServerOnline = true;
|
||||||
InformationModel.CanStartServer = false;
|
InformationModel.CanStartServer = false;
|
||||||
|
|||||||
@@ -8,8 +8,11 @@
|
|||||||
Title="MainWindow" Height="450" Width="800">
|
Title="MainWindow" Height="450" Width="800">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Button Content="Start Server" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Command="{Binding ServerStartCommand}" IsEnabled="{Binding InformationModel.CanStartServer}"/>
|
<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"/>
|
<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>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
BIN
Server/img/offline.png
Normal file
BIN
Server/img/offline.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 762 B |
BIN
Server/img/online.png
Normal file
BIN
Server/img/online.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 742 B |
Reference in New Issue
Block a user