merge Setup branch into develop #1
@@ -10,7 +10,11 @@ namespace Server.Models
|
|||||||
class Information : ObservableObject
|
class Information : ObservableObject
|
||||||
{
|
{
|
||||||
public bool CanStartServer { get; set; }
|
public bool CanStartServer { get; set; }
|
||||||
|
|
||||||
public bool ServerOnline { get; set; }
|
public bool ServerOnline { get; set; }
|
||||||
|
public string ServerStatus { get {
|
||||||
|
if (ServerOnline) return "Online";
|
||||||
|
return "Offline";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace Server.Models
|
|||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
|
|
||||||
|
|
||||||
public ServerClient(TcpClient client)
|
public ServerClient(TcpClient client)
|
||||||
{
|
{
|
||||||
tcpClient = client;
|
tcpClient = client;
|
||||||
@@ -75,6 +76,7 @@ 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}");
|
||||||
//TODO implement ways to handle the message
|
//TODO implement ways to handle the message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using SharedClientServer;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -13,13 +14,30 @@ namespace Server.Models
|
|||||||
private TcpListener listener;
|
private TcpListener listener;
|
||||||
private List<ServerClient> serverClients;
|
private List<ServerClient> serverClients;
|
||||||
public bool Started = false;
|
public bool Started = false;
|
||||||
|
private static readonly object padlock = new object();
|
||||||
|
private static ServerCommunication instance = null;
|
||||||
|
|
||||||
public ServerCommunication(TcpListener listener)
|
private ServerCommunication()
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
listener = new TcpListener(IPAddress.Any, 5555);
|
||||||
serverClients = new List<ServerClient>();
|
serverClients = new List<ServerClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ServerCommunication INSTANCE
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (padlock)
|
||||||
|
{
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new ServerCommunication();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
listener.Start();
|
listener.Start();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace Server.ViewModels
|
namespace Server.ViewModels
|
||||||
{
|
{
|
||||||
@@ -16,20 +17,23 @@ namespace Server.ViewModels
|
|||||||
private ServerCommunication serverCommunication;
|
private ServerCommunication serverCommunication;
|
||||||
public ICommand ServerStartCommand { get; set; }
|
public ICommand ServerStartCommand { get; set; }
|
||||||
public Information InformationModel { get; set; }
|
public Information InformationModel { get; set; }
|
||||||
|
private MainWindow mainWindow;
|
||||||
|
|
||||||
public MainViewModel()
|
public MainViewModel(MainWindow mainWindow)
|
||||||
{
|
{
|
||||||
|
this.mainWindow = mainWindow;
|
||||||
Debug.WriteLine("init mainviewmodel");
|
Debug.WriteLine("init mainviewmodel");
|
||||||
InformationModel = new Information();
|
InformationModel = new Information();
|
||||||
InformationModel.CanStartServer = true;
|
InformationModel.CanStartServer = true;
|
||||||
InformationModel.ServerOnline = false;
|
InformationModel.ServerOnline = false;
|
||||||
|
|
||||||
this.ServerStartCommand = new RelayCommand(() =>
|
this.ServerStartCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("connect button clicked");
|
Debug.WriteLine("connect button clicked");
|
||||||
if (serverCommunication == null)
|
if (serverCommunication == null)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("making new server communication");
|
Debug.WriteLine("making new server communication");
|
||||||
serverCommunication = new ServerCommunication(new TcpListener(IPAddress.Any,5555));
|
serverCommunication = ServerCommunication.INSTANCE;
|
||||||
}
|
}
|
||||||
if (!serverCommunication.Started)
|
if (!serverCommunication.Started)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
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 Content="{Binding InformationModel.ServerOnline}" HorizontalAlignment="Left" Margin="169,10,0,0" VerticalAlignment="Top"/>
|
<Label Name="serverStatusLabel" Content="{Binding InformationModel.ServerStatus}" HorizontalAlignment="Left" Margin="169,10,0,0" VerticalAlignment="Top"/>
|
||||||
<Label Content="Server Online:" HorizontalAlignment="Left" Margin="80,7,0,0" VerticalAlignment="Top"/>
|
<Label Content="Server Status:" HorizontalAlignment="Left" Margin="80,7,0,0" VerticalAlignment="Top"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ namespace Server
|
|||||||
{
|
{
|
||||||
|
|
||||||
// use mainviewmodel for the bindings of our methods
|
// use mainviewmodel for the bindings of our methods
|
||||||
DataContext = new MainViewModel();
|
DataContext = new MainViewModel(this);
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user