merge Setup branch into develop #1

Merged
SemvdH merged 71 commits from setupBranch into master 2020-10-21 18:59:02 +00:00
3 changed files with 14 additions and 6 deletions
Showing only changes of commit 73dc0b94de - Show all commits

View File

@@ -17,6 +17,7 @@ namespace Client
public int Port = 5555;
public bool Connected = false;
private string username;
public Callback OnSuccessfullConnect;
public Client(string username)
{
@@ -31,6 +32,7 @@ namespace Client
Debug.Write("finished connecting to server");
this.tcpClient.EndConnect(ar);
this.stream = tcpClient.GetStream();
OnSuccessfullConnect?.Invoke();
SendMessage(JSONConvert.ConstructUsernameMessage(username));
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete),null);
}

View File

@@ -28,13 +28,18 @@ namespace Client.Views
{
User user = new User(usernameTextbox.Text);
Client client = new Client(user.Username);
client.OnSuccessfullConnect = () =>
{
// because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread
Application.Current.Dispatcher.Invoke(delegate {
data.User = user;
data.Client = client;
MainWindow startWindow = new MainWindow();
startWindow.Show();
this.Close();
});
};
data.User = user;
data.Client = client;
MainWindow startWindow = new MainWindow();
startWindow.Show();
this.Close();
}
}
}

View File

@@ -6,6 +6,7 @@ using System.Text;
namespace SharedClientServer
{
public delegate void Callback();
class ClientServerUtil
{
// creates a message array to send to the server or to clients