public static void Connect(string host, int port, ClientErrorWrapper showError, ConnectionUpdate connectionUpdate, GameUpdateWrapper update) { _host = host; _port = port; _showError = showError; _connectionUpdate = connectionUpdate; _update = update; new Thread(() => { _proxy = new DataExchange(host, port, ConnectionUpdated, update).GetProxy(); }).Start(); _faultTimer = new System.Timers.Timer(5 * 1000) { AutoReset = false }; _faultTimer.Elapsed += Reconnecting; }
public DataExchange(string host, int port, ConnectionUpdate connectionUpdate, GameUpdateWrapper update) { _update = update; _connectionUpdate = connectionUpdate; var uri = (host == null || host.Trim().Length == 0 || host.ToLower().Equals("localhost") || host.Equals("127.0.0.1")) ? String.Format("net.tcp://localhost:{0}/CheckersAppServer", port) : String.Format("net.tcp://{0}:{1}/CheckersAppServer", host.Trim(), port); _site = new InstanceContext(this); _binding = new NetTcpBinding { OpenTimeout = _timeout, SendTimeout = _timeout, ReceiveTimeout = _timeout, CloseTimeout = _timeout }; _proxy = new CheckersServiceClient(_site, _binding, new EndpointAddress(uri)); _proxy.InnerDuplexChannel.Opened += (sender, args) => { _connectionUpdate?.Invoke(ConnectionState.Opened); }; _proxy.InnerDuplexChannel.Opening += (sender, args) => { _connectionUpdate?.Invoke(ConnectionState.Opening); }; _proxy.InnerDuplexChannel.Closed += (sender, args) => { _connectionUpdate?.Invoke(ConnectionState.Closed); }; _proxy.InnerDuplexChannel.Faulted += (sender, args) => { _connectionUpdate?.Invoke(ConnectionState.Faulted); }; }
public virtual void UpdateHandler(ConnectionUpdate update) { throw new InvalidOperationException("ConnectionUpdate is a notification and not valid for external requests."); }