void im_RegisterFailed(object sender, IMErrorEventArgs e) { this.BeginInvoke(new MethodInvoker(delegate { status.Text = "Register failed!"; })); }
virtual protected void OnLoginFailed(IMErrorEventArgs e) { if (LoginFailed != null) { LoginFailed(this, e); } }
virtual protected void OnRegisterFailed(IMErrorEventArgs e) { if (RegisterFailed != null) { RegisterFailed(this, e); } }
void SetupConn() // Setup connection and login { client = new TcpClient(Server, Port); // Connect to the server. netStream = client.GetStream(); ssl = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateCert)); ssl.AuthenticateAsClient("InstantMessengerServer"); // Now we have encrypted connection. br = new BinaryReader(ssl, Encoding.UTF8); bw = new BinaryWriter(ssl, Encoding.UTF8); // Receive "hello" int hello = br.ReadInt32(); if (hello == IM_Hello) { // Hello OK, so answer. bw.Write(IM_Hello); bw.Write(reg ? IM_Register : IM_Login); // Login or register bw.Write(UserName); bw.Write(Password); bw.Flush(); byte ans = br.ReadByte(); // Read answer. if (ans == IM_OK) // Login/register OK { if (reg) { OnRegisterOK(); // Register is OK. } OnLoginOK(); // Login is OK (when registered, automatically logged in) Receiver(); // Time for listening for incoming messages. } else { IMErrorEventArgs err = new IMErrorEventArgs((IMError)ans); if (reg) { OnRegisterFailed(err); } else { OnLoginFailed(err); } } } if (_conn) { CloseConn(); } }
void SetupConn() { client = new TcpClient(Server, Port); netStream = client.GetStream(); ssl = new SslStream(netStream, false, new RemoteCertificateValidationCallback(ValidateCert)); ssl.AuthenticateAsClient("InstantMessengerServer"); br = new BinaryReader(ssl, Encoding.UTF8); bw = new BinaryWriter(ssl, Encoding.UTF8); int hello = br.ReadInt32(); if (hello == IM_Hello) { bw.Write(IM_Hello); bw.Write(reg ? IM_Register : IM_Login); bw.Write(UserName); bw.Write(Password); bw.Flush(); byte ans = br.ReadByte(); if (ans == IM_OK) { if (reg) { OnRegisterOK(); } OnLoginOK(); Receiver(); } else { IMErrorEventArgs err = new IMErrorEventArgs((IMError)ans); if (reg) { OnRegisterFailed(err); } else { OnLoginFailed(err); } } } if (_conn) { CloseConn(); } }