Beispiel #1
0
 public void _OtherUnRegister(Beetle.IChannel channel, Logic.UnRegister e)
 {
     Invoke(new Action <Logic.UnRegister>(o =>
     {
         lstUsers.Items.Remove(o.User);
     }), e);
 }
Beispiel #2
0
 private void OnConnect()
 {
     try
     {
         txtError.Text = "";
         uint   dummy          = 0;
         byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
         BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);
         BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));
         BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);
         mChannel = TcpServer.CreateClient(txtIPAddress.Text, 9001);
         mChannel.Socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
         mChannel.ChannelError    += onerror;
         mChannel.ChannelDisposed += ondisposed;
         mChannel.SetPackage <Logic.HeadSizePage>();
         mChannel.Package.ReceiveMessage = OnReceive;
         mChannel.BeginReceive();
         Logic.Register register = new Logic.Register();
         register.Name = txtUserName.Text;
         mChannel.Send(register);
     }
     catch (Exception e_)
     {
         MessageBox.Show(this, e_.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #3
0
        public void _ReceiveSay(Beetle.IChannel channel, Logic.Say e)
        {
            string message = string.Format(@"\viewkind4\uc1\pard\sa200\sl276\slmult1\lang2052\f0\cf1\fs22 {0} \cf0 {2} IP:{1} \cf0\line {3}",
                                           e.User.Name, e.User.IP, DateTime.Now, e.Body);

            Invoke(new Action <string>(msg => { addSay(msg); }), message);
        }
Beispiel #4
0
 public void _OnLogin(Beetle.IChannel channel, Logic.RegisterResponse e)
 {
     Logic.ListUsers list = new Logic.ListUsers();
     channel.Send(list);
     Invoke(new Action <object>(o =>
     {
         toolStrip2.Enabled = false;
         groupBox2.Enabled  = true;
     }), new object());
 }
Beispiel #5
0
 public void _OthreRegister(Beetle.IChannel channel, Logic.OnRegister e)
 {
     Invoke(new Action <Logic.OnRegister>(o =>
     {
         if (!lstUsers.Items.Contains(o.User))
         {
             lstUsers.Items.Add(o.User);
         }
     }), e);
 }
Beispiel #6
0
 public void _OnList(Beetle.IChannel channel, Logic.ListUsersResponse e)
 {
     Invoke(new Action <Logic.ListUsersResponse>(o =>
     {
         lstUsers.Items.Clear();
         foreach (Logic.UserInfo item in o.Users)
         {
             lstUsers.Items.Add(item);
         }
     }), e);
 }
Beispiel #7
0
        public static int Send(Beetle.IChannel _channel, byte[] vBuf, bool hasCrLf)
        {
            if (vBuf.Length < 1)
            {
                return(0);
            }
            if (_channel.IsDisposed)
            {
                return(-1);
            }

            bool _ok = false;

            // 处理 CrLf
            List <byte> _buf = new List <byte>(vBuf);

            if (hasCrLf)
            {
                _buf.Add(10);
                _buf.Add(13);
            }

            try
            {
                Beetle.BytesMessage _bbm = new Beetle.BytesMessage();
                _bbm.Value = _buf.ToArray();
                _ok        = _channel.Send(_bbm);
            }
            catch (Exception e_)
            {
                MessageBox.Show("-103:" + e_.Message);
                //Console.WriteLine(e_.Message);
                return(-103);
            }
            return(_ok ? _buf.Count : 0);
        }
Beispiel #8
0
 private void OnConnect()
 {
     try
     {
         txtError.Text = "";
         uint dummy = 0;
         byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
         BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);
         BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));
         BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);
         mChannel = TcpServer.CreateClient(txtIPAddress.Text, 9001);
         mChannel.Socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
         mChannel.ChannelError += onerror;
         mChannel.ChannelDisposed += ondisposed;
         mChannel.SetPackage<Logic.HeadSizePage>();
         mChannel.Package.ReceiveMessage = OnReceive;
         mChannel.BeginReceive();
         Logic.Register register = new Logic.Register();
         register.Name = txtUserName.Text;
         mChannel.Send(register);
     }
     catch (Exception e_)
     {
         MessageBox.Show(this, e_.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #9
0
 public HeadSizePackage(Beetle.IChannel channel) : base(channel)
 {
 }