コード例 #1
0
ファイル: Client.cs プロジェクト: Joniator/Chat
        /// <summary>
        /// Versucht, sich beim Server zu registrieren.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public bool Register(string username, string password)
        {
            if (tcpClient == null || !IsConnected)
            {
                settings  = SettingsDatabase.Load();
                tcpClient = new TcpClient(settings.IpAddress, settings.Port);
                streamRW  = new StreamRW(tcpClient.GetStream());

                Message message = new Message()
                {
                    content  = new Content(ContentType.Register, username, password),
                    sender   = null,
                    sendTime = DateTime.Now
                };

                Send(message);
                string buffer = streamRW.ReadLine();
                if (buffer == "Register succesfull")
                {
                    Log.WriteLine("[Client][{0}] {1} registered.", DateTime.Now, username);
                }
                else if (buffer != "")
                {
                    MessageBox.Show(buffer);
                    return(false);
                }
                Disconnect("Registration finished");
                return(true);
            }
            return(false);
        }
コード例 #2
0
 public MainWindow()
 {
     InitializeComponent();
     client                    = new Client();
     client.userUI             = this;
     settings                  = SettingsDatabase.Load();
     textBoxServerPort.Text    = settings.Port.ToString();
     textBoxServerIP.Text      = settings.IpAddress;
     client.OnMessageReceived += AddChat;
 }