//GET MEDIA //Geting picture from server private void action_server_get_media() { string ext = _chatstream.Read(); string snumbytes = _chatstream.Read(); int numbytes = int.Parse(snumbytes); //int numbytes=0; byte[] readbytes = _chatstream.ReadBinary(numbytes); if (readbytes == null) { //Console.WriteLine("Error getting picture"); responseData = "server> Error getting picture"; action_message(); return; } FileStream f = new FileStream(_currentpath + "\\" + nickname + "_received." + ext, FileMode.Create); f.Write(readbytes, 0, numbytes); f.Close(); // shpR.Text=""+(numbytes/1000)+"KB"; rtb.SelectionStart = rtb.Text.Length; _media_id++; string c_currentpath = _currentpath.Replace(" ", "@"); rtb.SelectedText = "\nfile:///" + c_currentpath + "\\" + nickname + "_received" + _media_id + "." + ext; File.Copy(_currentpath + "\\" + nickname + "_received." + ext, _currentpath + "\\" + nickname + "_received" + _media_id + "." + ext, true); //Play the sound //MediaPlayer.Play(this.rtb.Handle,_currentpath +"\\"+nickname+"_received.ext"); }
public bool Authenticate() { //if we had attempted a password before //do not get new response //just process the old response ( which is password prompt) if (!_passwordattempted) { responseData = _chatstream.Read(); } //Console.Write("**" +responseData+"**"); //step 1 if (responseData.IndexOf(AuthenticationProtocolValues.COMMAND_PROMPT) >= 0) { if (rb_register.Checked) { _chatstream.Write(rb_register.Text); } if (rb_login.Checked) { _chatstream.Write(rb_login.Text); } responseData = _chatstream.Read(); //Console._chatstream.Write(responseData); } //step 2 if (responseData.IndexOf(AuthenticationProtocolValues.USERID_PROMPT) >= 0) { rb_register.Enabled = false; rb_login.Enabled = false; _chatstream.Write(tb_username.Text); responseData = _chatstream.Read(); //Console.Write(responseData); } //step 3 .. up to 3 tries if (responseData.IndexOf(AuthenticationProtocolValues.PASSWORD_PROMPT) >= 0) { //we are processing the password, // do not allow user to change userid tb_username.Enabled = false; _chatstream.Write(tb_userpassword.Text); responseData = _chatstream.Read(); //Console.Write(responseData); //password verification has been attempted if (rb_login.Checked) { _passwordattempted = true; } } //show the message from server on results of //the authenication MessageBox.Show(FormatMessage(responseData)); if (responseData.IndexOf(AuthenticationProtocolValues.QUIT_MSG) == 0) { // _authenticated = false; this.DialogResult = DialogResult.Abort; this.Close(); // authForm.Close(); } if (responseData.IndexOf(AuthenticationProtocolValues.AUTENTICATED_MSG) == 0) { // _authenticated = true; this.DialogResult = DialogResult.OK; this.Close(); // authForm.Close(); } if (responseData.IndexOf(AuthenticationProtocolValues.USER_ALREADY_LOGGED_IN) == 0) { // _authenticated = false; this.DialogResult = DialogResult.No; this.Close(); //authForm.Close(); } return(true); //dummy return }