/// <summary> /// Event enabled if client connect to server via TCP /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void ServerConnected(object sender, EventArgs e) { client.TCPSendMessageToServer("ConnectionSucessful", NetworkUtil.GetMachineName()); window.Dispatcher.Invoke(async() => { // request all the registered patient, exp from scheduler client.TCPSendMessageToServer("requestInitialPatient", ""); // Injection Syncing... // clear all previous injection InjectionsManager.injections.Clear(); // request all the injection client.TCPSendMessageToServer("requestInitialInjection", ""); if (progressingDialog.IsVisible) { await window.HideMetroDialogAsync(progressingDialog); } if (simultaneousErrorDialog.IsVisible) { await window.HideMetroDialogAsync(simultaneousErrorDialog); } if (twoChoiceDialog.IsVisible) { await window.HideMetroDialogAsync(twoChoiceDialog); } await window.ShowMessageAsync("Connection to server succesful", "Server Name: " + client.servername + "\nServer IP:" + client.serverip); }); }
private static async void StartServer(object sender, RoutedEventArgs e) { if (System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners().Any(p => p.Port == 15000)) { if (!simultaneousErrorDialog.IsVisible) { await window.ShowMetroDialogAsync(simultaneousErrorDialog); } simultaneousErrorDialog.MessageText.Content = "Error when starting server- UDP port already occupied. Check whether there is another instance running"; Console.Out.WriteLine("[NetworkManager] error when starting server- UDP port already occupied. Check whether there is another instance running"); return; } server = new Server(); connected = true; clientNumber = 0; clientCount = 0; //client view object for displaying in the network page ClientViewObject.Add(clientNumber, NetworkUtil.GetMachineName(), NetworkUtil.GetLocalIPAddress()); //TODO: add -= when server shut down? server.MessageReceivedFromClientEvent += MessageReceivedFromClient; server.ClientConnectedEvent += ClientConnected; server.ClientDisconnectedEvent += ClientDisconnected; //load all patient in registered patient after starting server, the client will load the patient via requesting PatientManager.LoadAllPatientFromSchedular(); PatientManager.LoadAllPatient(); //load all the injection after starting server, the client will load the injection via contacting with server InjectionsManager.loadAllInjections(); if (twoChoiceDialog.IsVisible) { await window.HideMetroDialogAsync(twoChoiceDialog); } await window.ShowMessageAsync("No server found. \nStarted as server instead!", "Server Name: " + NetworkUtil.GetMachineName() + "\nServer IP:" + NetworkUtil.GetLocalIPAddress()); }
private void UDPMessageReceived(object sender, UDPNetworking.MessageRecievedEventArgs e) { if (e.message == "connectionrequest") { uDPNetworking.UDPSend(e.ipAddress, 14999, "connectionaccepted" + "_" + NetworkUtil.GetMachineName()); } }