wpf sucks v2
This commit is contained in:
@@ -22,11 +22,13 @@ namespace Client
|
||||
public Client()
|
||||
{
|
||||
this.tcpClient = new TcpClient();
|
||||
Debug.WriteLine("Starting connect to server");
|
||||
tcpClient.BeginConnect("localhost", Port, new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
private void OnConnect(IAsyncResult ar)
|
||||
{
|
||||
Debug.Write("finished connecting to server");
|
||||
this.tcpClient.EndConnect(ar);
|
||||
this.stream = tcpClient.GetStream();
|
||||
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete),null);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Client
|
||||
_model = new Model();
|
||||
ButtonCommand = new RelayCommand(() =>
|
||||
{
|
||||
ClickCheck();
|
||||
Client client = new Client();
|
||||
});
|
||||
|
||||
_lobbies = new List<Lobby>();
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace Server.Models
|
||||
}
|
||||
}
|
||||
|
||||
public int ClientsConnected{ get { return ServerCommunication.INSTANCE.ClientsConnected; } }
|
||||
public int ClientsConnected{ get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@ namespace Server.Models
|
||||
private TcpListener listener;
|
||||
private List<ServerClient> serverClients;
|
||||
public bool Started = false;
|
||||
public int ClientsConnected { get { return serverClients.Count; } }
|
||||
public List<Lobby> lobbies;
|
||||
private Dictionary<Lobby, List<ServerClient>> serverClientsInlobbies;
|
||||
public int ClientsConnected { get; set; }
|
||||
public Action newClientAction;
|
||||
|
||||
/// <summary>
|
||||
/// use a padlock object to make sure the singleton is thread-safe
|
||||
@@ -33,6 +34,7 @@ namespace Server.Models
|
||||
serverClients = new List<ServerClient>();
|
||||
lobbies = new List<Lobby>();
|
||||
serverClientsInlobbies = new Dictionary<Lobby, List<ServerClient>>();
|
||||
ClientsConnected = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,6 +64,7 @@ namespace Server.Models
|
||||
Debug.WriteLine($"================================================\nStarted Accepting clients at {DateTime.Now}\n================================================");
|
||||
Started = true;
|
||||
// when we have accepted a tcp client, call the onclientconnected callback method
|
||||
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
||||
}
|
||||
|
||||
@@ -72,10 +75,12 @@ namespace Server.Models
|
||||
private void OnClientConnected(IAsyncResult ar)
|
||||
{
|
||||
// stop the acceptation
|
||||
TcpClient tcpClient = listener.EndAcceptTcpClient(ar);
|
||||
Console.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
|
||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||
Debug.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
|
||||
newClientAction.Invoke();
|
||||
// create a new serverclient object and add it to the list
|
||||
serverClients.Add(new ServerClient(tcpClient));
|
||||
ClientsConnected++;
|
||||
//start listening for new tcp clients
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Server.ViewModels
|
||||
{
|
||||
class MainViewModel : ObservableObject
|
||||
{
|
||||
private ServerCommunication serverCommunication;
|
||||
public ServerCommunication serverCommunication { get; set; }
|
||||
public ICommand ServerStartCommand { get; set; }
|
||||
public Information InformationModel { get; set; }
|
||||
private MainWindow mainWindow;
|
||||
@@ -28,6 +28,11 @@ namespace Server.ViewModels
|
||||
InformationModel = new Information();
|
||||
InformationModel.CanStartServer = true;
|
||||
InformationModel.ServerOnline = false;
|
||||
InformationModel.ClientsConnected = 0;
|
||||
serverCommunication.newClientAction = () =>
|
||||
{
|
||||
InformationModel.ClientsConnected++;
|
||||
};
|
||||
//BitmapImage onlineImg = new BitmapImage(new Uri(@"/img/online.png",UriKind.Relative));
|
||||
//BitmapImage offlineImg = new BitmapImage(new Uri(@"/img/offline.png", UriKind.Relative));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user