private void Initialize() { _callbacks = new Dictionary <string, Action <ReceivedMessage> >(); _updateCallbacks = new Dictionary <string, Action <ReceivedMessage> >(); _updateCallbackQueue = new Queue <ReceivedMessage>(); _serializer = new MsgPackCliSerializer(); _simplSocketClient.MessageReceived += MessageReceived; _simplSocketClient.Connected += (s, e) => { Connected?.Invoke(s, e); }; _simplSocketClient.Disconnected += (s, e) => { Disconnected?.Invoke(s, e); }; _simplSocketClient.ConnectionAttempt += (s, e) => { ConnectionAttempt?.Invoke(s, e); }; }
private async Task KeepConnectedAsync(IPEndPoint endPoint) { while (_connectionMode == ConnectionModes.fixedEndPoint) { if (!_isConnected) { ConnectionAttempt?.Invoke(this, new ServerEndpointArgs(endPoint)); SafeConnect(endPoint); await Task.Delay(1000); } } }
private async Task KeepConnectedAsync(string serverName) { var ipaddresses = NetworkHelper.GetCurrentIpv4Addresses(); while (_connectionMode == ConnectionModes.Discovery) { // Check if not connected if (!_isConnected) { lock (_beaconsLock) { // if (_beacons != null) { foreach (var beacon in _beacons) { ConnectionAttempt?.Invoke(this, new ServerEndpointArgs(beacon.Address)); if (SafeConnect(beacon.Address)) { break; } // Check if IP adress received is a local adress if (ipaddresses.Contains(beacon.Address.Address)) { var loopBackEndPoint = new IPEndPoint(IPAddress.Loopback, beacon.Address.Port); ConnectionAttempt?.Invoke(this, new ServerEndpointArgs(loopBackEndPoint)); if (SafeConnect(loopBackEndPoint)) { break; } } } } } } await Task.Delay(1000); } }