public void Connect(string endPointAddress) { if (this._lucidServer != null) { Disconnect(); } EndpointAddress serverEndpointAddress; try { serverEndpointAddress = new EndpointAddress(endPointAddress); } catch { // bad url throw new Exception("Bad server URL: " + endPointAddress); } Binding binding = new NetTcpBinding(SecurityMode.None, true); binding.ReceiveTimeout = TimeSpan.FromSeconds(10); binding.SendTimeout = TimeSpan.FromSeconds(10); binding.OpenTimeout = TimeSpan.FromSeconds(10); var factory = new ChannelFactory<ILucidService>(binding, serverEndpointAddress); this._lucidServer = factory.CreateChannel(); // let server know we are available this._lucidServer.RegisterClient(); Inv.Log.Log.WriteMessage("Connected to server " + endPointAddress); }
public void Disconnect() { // disconnect was in race condition with runJob, because // disconnect could set _lucidServer to null // while runJob has been trying to upload results lock (this) { if (this._lucidServer != null) { disableTimer(_timer); try { this._lucidServer.UnRegisterClient(); ((IChannel)this._lucidServer).Close(); } catch (CommunicationException) { // happens when new job started or server quit // during computation } this._lucidServer = null; } } }