private void InitOnlineCommunicationClient() { List<string> ListServerIP = new List<string>(); bool TryConnecting = true; //Loop through every connections until you find a working server or none do { try { IniFile ConnectionInfo = IniFile.ReadFromFile("Connection Info.ini"); if (ListServerIP.Count == 0) { ListServerIP = ConnectionInfo.ReadAllValues("Communication Client Info"); } int ServerIndex = RandomHelper.Next(ListServerIP.Count); string[] ArraySelectedServerInfo = ListServerIP[ServerIndex].Split(','); ListServerIP.RemoveAt(ServerIndex); OnlineCommunicationClient.Connect(IPAddress.Parse(ArraySelectedServerInfo[0]), int.Parse(ArraySelectedServerInfo[1])); TryConnecting = false; } catch (Exception) { } } while (TryConnecting); }
public async Task DownloadVerificationTestItems(int level) { if (!CommunicationClient.IsConnected) { await CommunicationClient.Connect(); } if (Instrument.CompositionType == CorrectorType.PTZ) { await DownloadTemperatureTestItems(level); await DownloadPressureTestItems(level); } if (Instrument.CompositionType == CorrectorType.T) { await DownloadTemperatureTestItems(level); } if (Instrument.CompositionType == CorrectorType.P) { await DownloadPressureTestItems(level); } await CommunicationClient.Disconnect(); }
private async void Initialize() { _mainThread = Thread.CurrentThread.ManagedThreadId; CoreLog.Log(CoreLogLevel.Initialisation, "SampSharp GameMode Client"); CoreLog.Log(CoreLogLevel.Initialisation, "-------------------------"); CoreLog.Log(CoreLogLevel.Initialisation, $"v{CoreVersion.Version.ToString(3)}, (C)2014-2020 Tim Potze"); CoreLog.Log(CoreLogLevel.Initialisation, "Multi-process run mode is active. FOR DEVELOPMENT PURPOSES ONLY!"); CoreLog.Log(CoreLogLevel.Initialisation, "Run your server in hosted run mode for production environments. See https://sampsharp.net/running-in-production for more information."); CoreLog.Log(CoreLogLevel.Initialisation, ""); AppDomain.CurrentDomain.ProcessExit += (sender, args) => { CoreLog.Log(CoreLogLevel.Info, "Shutdown signal received"); ShutDown(); if (_mainRoutine != null && !_mainRoutine.IsCompleted) { _mainRoutine.Wait(); } if (_networkingRoutine != null && !_networkingRoutine.IsCompleted) { _networkingRoutine.Wait(); } }; CoreLog.Log(CoreLogLevel.Info, $"Connecting to the server via {CommunicationClient}..."); await CommunicationClient.Connect(); _running = true; CoreLog.Log(CoreLogLevel.Info, "Set up networking routine..."); StartNetworkingRoutine(); CoreLog.Log(CoreLogLevel.Info, "Connected! Waiting for server announcement..."); ServerCommandData data; do { data = await _commandWaitQueue.WaitAsync(); // Could receive ticks if reconnecting. } while (data.Command == ServerCommand.Tick); if (!VerifyVersionData(data)) { return; } CoreLog.Log(CoreLogLevel.Info, "Initializing game mode provider..."); _gameModeProvider.Initialize(this); CoreLog.Log(CoreLogLevel.Info, "Sending start signal to server..."); Send(ServerCommand.Start, new[] { (byte)_startBehaviour }); CoreLog.Log(CoreLogLevel.Info, "Set up main routine..."); _mainRoutine = MainRoutine(); }
private void ButtonConnectServer_Click(object sender, RoutedEventArgs e) { if (!_client.IsConnected) { string server_ip = ComboBoxServerIP.Text.Trim(); string server_port = TextBoxServerPort.Text.Trim(); _client.Connect(server_ip, server_port); ButtonConnectServer.Content = "Disconnect"; } else { SendTcpMsg(CommunicationConstants.COMM_DISCONNECT_MSG); ButtonConnectServer.Content = "Connect"; } }
//private ServerListener serverListener; public SinglePlayerGameModel() { string resultCommand; communicationClient = new CommunicationClient(); //TODO get ip and port from Settings communicationClient.Connect(8000, "127.0.0.1"); communicationClient.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e) { ServerResponse = communicationClient.CommandFromUser; }; // TcpClient tcpClient = new TcpClient(); // this.serverListener = new ServerListener(tcpClient, new StreamReader(tcpClient.GetStream())); }
/// <summary> /// Constructor. /// </summary> /// <param name="settingsModel">Settings model.</param> public SinglePlayerGameModel(ISettingsModel settingsModel) { //Initializes members. this.communicationClient = new CommunicationClient(); this.settingsModel = settingsModel; communicationClient.Connect(settingsModel.Port, settingsModel.IpAddress); //Sets property changed delegate. communicationClient.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e) { ServerResponse = communicationClient.CommandFromUser; }; }
private async Task LiveReadItems(Dictionary <int, ReadingStabilizer> liveReadItems) { await CommunicationClient.Connect(); do { foreach (var item in liveReadItems) { var liveValue = await CommunicationClient.LiveReadItemValue(item.Key); item.Value.ValueQueue.Enqueue(liveValue.NumericValue); Container.Resolve <IEventAggregator>() .PublishOnBackgroundThread(new LiveReadEvent(item.Key, liveValue.NumericValue)); } } while (liveReadItems.Any(x => !x.Value.IsStable())); await CommunicationClient.Disconnect(); }
private async void Initialize() { CoreLog.Log(CoreLogLevel.Initialisation, "SampSharp GameMode Client"); CoreLog.Log(CoreLogLevel.Initialisation, "-------------------------"); CoreLog.Log(CoreLogLevel.Initialisation, $"v{CoreVersion.Version.ToString(3)}, (C)2014-2019 Tim Potze"); CoreLog.Log(CoreLogLevel.Initialisation, ""); _mainThread = Thread.CurrentThread.ManagedThreadId; _running = true; CoreLog.Log(CoreLogLevel.Info, $"Connecting to the server via {CommunicationClient}..."); await CommunicationClient.Connect(); CoreLog.Log(CoreLogLevel.Info, "Set up networking routine..."); StartNetworkingRoutine(); CoreLog.Log(CoreLogLevel.Info, "Connected! Waiting for server announcement..."); ServerCommandData data; do { data = await _commandWaitQueue.WaitAsync(); // Could receive ticks if reconnecting. } while (data.Command == ServerCommand.Tick); if (!VerifyVersionData(data)) { return; } CoreLog.Log(CoreLogLevel.Info, "Initializing game mode provider..."); _gameModeProvider.Initialize(this); CoreLog.Log(CoreLogLevel.Info, "Sending start signal to server..."); Send(ServerCommand.Start, new[] { (byte)_startBehaviour }); CoreLog.Log(CoreLogLevel.Info, "Set up main routine..."); MainRoutine(); }