made serverConnection true thread safe singleton
This commit is contained in:
@@ -10,7 +10,11 @@ namespace Server.Models
|
||||
class Information : ObservableObject
|
||||
{
|
||||
public bool CanStartServer { get; set; }
|
||||
|
||||
public bool ServerOnline { get; set; }
|
||||
public string ServerStatus { get {
|
||||
if (ServerOnline) return "Online";
|
||||
return "Offline";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Server.Models
|
||||
private byte[] buffer = new byte[1024];
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
|
||||
|
||||
public ServerClient(TcpClient client)
|
||||
{
|
||||
@@ -75,6 +76,7 @@ namespace Server.Models
|
||||
/// <param name="message">the incoming message</param>
|
||||
private void HandleIncomingMessage(byte[] message)
|
||||
{
|
||||
Debug.WriteLine($"Got message from client : {message}");
|
||||
//TODO implement ways to handle the message
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using SharedClientServer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
@@ -13,13 +14,30 @@ namespace Server.Models
|
||||
private TcpListener listener;
|
||||
private List<ServerClient> serverClients;
|
||||
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>();
|
||||
}
|
||||
|
||||
public static ServerCommunication INSTANCE
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (padlock)
|
||||
{
|
||||
if (instance == null) {
|
||||
instance = new ServerCommunication();
|
||||
}
|
||||
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
listener.Start();
|
||||
|
||||
Reference in New Issue
Block a user