private void Window_Loaded(object sender, RoutedEventArgs e) { Callback = new ClientCallback(); ClientCallback.displayChallenge = DisplayChallenge; ClientCallback.updateUsers = UpdateUsers; ClientCallback.updateInfo = UpdateInfo; InstanceContext instanceContext = new InstanceContext(new ClientCallback()); client = new CheckersServiceClient(instanceContext); client.setClient(Username); //PlayersList.ItemsSource = client.getOnlineUsers(Username); }
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; }
private void ButtonConnect_Click(object sender, RoutedEventArgs e) { //CheckersServiceClient client = new CheckersServiceClient(); InstanceContext instanceContext = new InstanceContext(new ClientCallback()); CheckersServiceClient client = new CheckersServiceClient(instanceContext); if (client.LogIn(tbUsername.Text, tbPassword.Password)) { Online online = new Online(); online.usrLbl.Content = "ID:" + tbUsername.Text.ToUpper(); online.Username = tbUsername.Text.ToString(); // online.Callback = call; this.Close(); online.Show(); } else { MessageBox.Show("Failed to connect. please check the username and password."); } }
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); }; }