Ejemplo n.º 1
0
        private void JoinToChatRoom()
        {
            if (chan == null && txtName.Text.Trim().Length != 0)
            {
                chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, false);

                // Create an instance of the remote object
                objChatWin           = new frmChatWin();
                objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                if (!objChatWin.remoteObj.JoinToChatRoom(txtName.Text))
                {
                    MessageBox.Show(txtName.Text + " already joined, please try with different name");
                    ChannelServices.UnregisterChannel(chan);
                    chan = null;
                    objChatWin.Dispose();
                    return;
                }
                objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();

                objChatWin.yourName = txtName.Text;

                this.Hide();
                objChatWin.Show();
            }
        }
Ejemplo n.º 2
0
        private void JoinToChatRoom()
        {
            if (chan == null && txtName.Text.Trim().Length != 0)
            {
                chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, false);

                // Create an instance of the remote object
                objChatWin = new frmChatWin();
                objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                if (!objChatWin.remoteObj.JoinToChatRoom(txtName.Text))
                {
                    MessageBox.Show(txtName.Text+ " already joined, please try with different name");
                    ChannelServices.UnregisterChannel(chan);
                    chan = null;
                    objChatWin.Dispose();
                    return;
                }
                objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();
                
                objChatWin.yourName= txtName.Text;

                this.Hide();
                objChatWin.Show();
                
            }
        }
Ejemplo n.º 3
0
        private void JoinToChatRoom()
        {
            if (chan == null && txtName.Text.Trim().Length != 0)
            {
                chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, false);
                try
                {
                    // Create an instance of the remote object
                    objChatWin           = new frmChatWin();
                    objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                    if (!objChatWin.remoteObj.JoinToChatRoom(txtName.Text))
                    {
                        MessageBox.Show(txtName.Text + " пользователь с таким именем уже находится в диаоге, выберите другое");
                        ChannelServices.UnregisterChannel(chan);
                        chan = null;
                        objChatWin.Dispose();
                        return;
                    }
                    objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();

                    objChatWin.yourName = txtName.Text;

                    this.Hide();
                    objChatWin.Show();
                }
                catch (System.Net.Sockets.SocketException)
                {
                    MessageBox.Show("Невозможно подсоединиться, технические неполадки на сервере", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                //// Create an instance of the remote object
                //objChatWin = new frmChatWin();
                //objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                //if (!objChatWin.remoteObj.JoinToChatRoom(txtName.Text))
                //{
                //    MessageBox.Show(txtName.Text+ " пользователь с таким именем уже находится в диаоге, выберите другое");
                //    ChannelServices.UnregisterChannel(chan);
                //    chan = null;
                //    objChatWin.Dispose();
                //    return;
                //}
                //objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();

                //objChatWin.yourName= txtName.Text;

                //this.Hide();
                //objChatWin.Show();
            }
        }
Ejemplo n.º 4
0
        private void JoinToServer()
        {
            if (chan == null)
            {
                chan = new TcpChannel();
                ChannelServices.RegisterChannel(chan, false);

                // Create an instance of the remote object
                objChatWin           = new frmChatWin();
                objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                objChatWinAdmin           = new frmChatWinAdmin();
                objChatWinAdmin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);

                try
                {
                    BaseInfo.ClientId = objChatWin.remoteObj.JoinToChatRoom();

                    if (BaseInfo.ClientId == -1)
                    {
                        MessageBox.Show(BaseInfo.ClientId + " already joined, please try with different id");
                        ChannelServices.UnregisterChannel(chan);
                        chan = null;
                        objChatWin.Dispose();
                        return;
                    }

                    if (BaseInfo.ClientId == 0)
                    {
                        //MessageBox.Show("You are admin!");
                        this.Hide();
                        objChatWinAdmin.Show();
                    }
                    else
                    {
                        this.Hide();
                        objChatWin.Show();
                    }
                }
                catch
                {
                    MessageBox.Show("Error! Try restart the server");
                    ChannelServices.UnregisterChannel(chan);
                    chan = null;
                    objChatWin.Dispose();
                }
            }
        }