コード例 #1
0
ファイル: MainForm.cs プロジェクト: cocodejam/simsimtalk
        private void optMenu(string[] str)
        {
            switch (str[1])
            {
            case "0":
                if (str[2].Equals("0"))
                {
                    MessageBox.Show("로그아웃 실패");
                }
                else if (str[2].Equals("1"))
                {
                    client.Disconnect(true);
                    if (thread != null)
                    {
                        thread.Abort();
                    }
                }
                break;

            case "1":       // 닉네임 변경
            {
                if (str[2].Equals("0"))
                {
                    MessageBox.Show("변경 실패하였습니다.");
                }

                else if (str[2].Equals("1"))
                {
                    Store.myInfo.setName(str[3]);         // my정보 수정
                    MessageBox.Show("이름이 변경되었습니다.");
                }
                break;
            }

            case "2":       // 비밀번호 변경
                if (str[2].Equals("0"))
                {
                    MessageBox.Show("비밀번호가 맞지 않습니다.");
                }
                else if (str[2].Equals("1"))
                {
                    opt.cPwd.changePassword();
                }
                break;

            case "3":       // 회원탈퇴

                if (str[2].Equals("0"))
                {
                    opt.drop.isDrop(false);
                    MessageBox.Show("정보가 올바르지 않습니다.");
                }
                else if (str[2].Equals("1"))
                {
                    opt.drop.isDrop(true);
                    isUserDrop = true;
                    this.Close();
                    //MessageBox.Show("탈퇴되었습니다.");
                }
                break;
            }
        }
コード例 #2
0
 private void DisconnectButton_Click(object sender, EventArgs e)
 {
     clientSocketForFileServer.Send(Encoding.UTF8.GetBytes("discon"));
     clientSocketForFileServer.Disconnect(false);
     setInterfaceToDisconnected();
 }
コード例 #3
0
      //LogIn is being done in a new thread, therefore INVOKEs are used to accessing main form thread.
      private void logIn()
      {
          clientSocketForAuthenticationServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);   //tcp socket initializing
          ipAddress         = IPAddress.Parse("127.0.0.1");
          remoteApplication = new IPEndPoint(ipAddress, Convert.ToInt32("9999"));
          try
          {
              clientSocketForAuthenticationServer.Connect(remoteApplication);   //client socket will connect to server socket
          }
          catch (Exception ex)
          {
              MessageBox.Show("socket.Connect(remoteApplication). Details:\n" + ex.ToString());
          }

          try
          {
              //Assuming neither username will be allowed to end with space nor password will be allowed to start with space
              byte[] authenticationInfo = Encoding.UTF8.GetBytes("clientRequest" + userNameBox.Text + " " + passwordBox.Text);
              clientSocketForAuthenticationServer.Send(authenticationInfo);
              Invoke(new Action(() =>
                {
                    logBox.Items.Add("Authentication request sent.");
                    logBox.SelectedIndex = logBox.Items.Count - 1;
                }));

              byte[] messageReceivedByte = new Byte[1024];
              clientSocketForAuthenticationServer.Receive(messageReceivedByte);

              string messageReceivedString = Encoding.UTF8.GetString(messageReceivedByte).Substring(0, Encoding.UTF8.GetString(messageReceivedByte).IndexOf("\0"));
              if (messageReceivedString == "rejected")
              {
                  Invoke(new Action(() =>
                    {
                        logBox.Items.Add("Authentication rejected, you may try again.");
                        logInButton.Enabled  = true;
                        logBox.SelectedIndex = logBox.Items.Count - 1;
                    }));
              }
              else
              {
                  Invoke(new Action(() =>
                    {
                        logBox.Items.Add("You are authenticated with token: " + BitConverter.ToInt32(messageReceivedByte, 0));
                        logBox.Items.Add("You are being forwarded to File Storage Client UI in a few seconds.");
                        logBox.SelectedIndex = logBox.Items.Count - 1;
                    }));
                  // backgroundWorkerForLogInConnection.CancelAsync();

                  //Thread.Sleep(5000);

                  Invoke(new Action(() =>
                    {
                        this.Hide();
                    }));
                  Application.Run(new Client(BitConverter.ToInt32(messageReceivedByte, 0)));
                  Invoke(new Action(() =>
                    {
                        Dispose();
                    }));
              }
              clientSocketForAuthenticationServer.Disconnect(false);
              clientSocketForAuthenticationServer.Close();
          }
          catch (Exception ex)
          {
              Invoke(new Action(() =>
                {
                    logBox.Items.Add(ex.ToString());
                }));
              Invoke(new Action(() =>
                {
                    logInButton.Enabled = true;
                }));
          }
      }
コード例 #4
0
 public void Disconnect()
 {
     _socket.Disconnect(true);
 }