/// <summary> /// Klik na tlacitko pripojeni k serveru. /// Pokud jsem offline, tak se skusim pripojit. /// Pokud jsem pripojen, tak se odpojim. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectBtn_Click( object sender, RoutedEventArgs e ) { if( State == WinState.Offline ) { SetState( WinState.InMiddle ); client = new ChatClient( this ); if( client.Connect( IPTB.Text, UsernameTB.Text ) ) SetState( WinState.InMiddle ); else SetState( WinState.Offline ); } else if( State == WinState.Connected ) { client.Disconnect(); } MessageTB.Focus(); }
/// <summary> /// Klik na tlacitko zapnuti serveru. /// Pokud jsme offline, tak se pokusi zalozit server a pripojit s clientem. /// Pokud hostujeme server, tak ho vypne. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HostBtn_Click( object sender, RoutedEventArgs e ) { if( State == WinState.Offline ) { SetState( WinState.InMiddle ); // Nez zacnu neco delat, tak vsechno zdisabluju server = new ChatServer( this ); client = new ChatClient( this ); if( server.Start() ) if( client.Connect( "127.0.0.1:4586", UsernameTB.Text ) ) // Pripojuji se na localhost, takze neresim textbox s IP SetState( WinState.Hosting ); else { // Pokud se pripojeni clienta nepodarilo, tak vypnu server server.Stop(); SetState( WinState.Offline ); } else // Pokud se vytvoreni serveru nepodarilo, tak se vratim do stavu offline SetState( WinState.Offline ); } else if( State == WinState.Hosting ) { // Kdyz hostuji, tak odpojim clienta a vypnu server client.Disconnect(); server.Stop(); } MessageTB.Focus(); }