Пример #1
0
 private void UDPMessageReceived(object sender, UDPNetworking.MessageRecievedEventArgs e)
 {
     if (e.message == "connectionrequest")
     {
         uDPNetworking.UDPSend(e.ipAddress, 14999, "connectionaccepted" + "_" + NetworkUtil.GetMachineName());
     }
 }
Пример #2
0
        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());
        }