Ejemplo n.º 1
0
        public bool UserLogonRequest()
        {
            #region

            TcpClientEx tcpclient = new TcpClientEx(
                ServerInfor._Ip.ToString(), Convert.ToInt16(ServerInfor._Port));
            SendUserValidCheck senduservalidcheck = new
                                                    SendUserValidCheck()
            {
                _UserInfor = _User
            };
            byte[] command = senduservalidcheck.GetProtocolCommand();
            tcpclient.Connect();
            tcpclient.SendToEndDevice(command);
            tcpclient.Receive();
            RecvUserCheckResult usercheckresult = new RecvUserCheckResult();
            tcpclient.Dispatcher(usercheckresult);
            tcpclient.Close();

            if (usercheckresult._Result._Success)
            {
                string message    = usercheckresult._Result._Message;
                int    splitindex = message.IndexOf("-");
                _User.uid          = message.Substring(0, splitindex);
                _User.userfullName = message.Substring(splitindex + 1, message.Length - splitindex - 1);
            }
            return(usercheckresult._Result._Success);

            #endregion
        }
Ejemplo n.º 2
0
        private void btnStartSend_Click(object sender, EventArgs e)
        {
            MethodInvoker gd = new MethodInvoker(() =>
            {
                TcpClientEx tcpclient = new TcpClientEx("192.168.159.104", 1005);

                SendFileSyn transfilesyn = new SendFileSyn();


                tcpclient.Connect();

                tcpclient.SendToEndDevice(transfilesyn.GetProtocolCommand());

                tcpclient.Receive();

                RecvFileAck transfileack         = new RecvFileAck();
                transfileack.OnStartingDownload += new EventHandler(StartingDownload);
                tcpclient.Dispatcher(transfileack);

                tcpclient.Close();
            });

            gd.BeginInvoke(null, null);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public void RegisterListen(IconController iconController)
        {
            #region

            TcpClientEx tcpclient = ChatClient.ConnectServer();

            SendRegisterClientListen sendregister = new SendRegisterClientListen()
            {
                _UserInfor = Logon._User
            };
            SendOnlineMarkup sendonlinemarkup = new SendOnlineMarkup()
            {
                _UserInfor = Logon._User
            };

            byte[] sendregistercommand = sendregister.GetProtocolCommand();
            byte[] sendonlinecommand   = sendonlinemarkup.GetProtocolCommand();
            tcpclient.SendToEndDevice(sendregistercommand);

            //可接收是否发送成功
            while (true)
            {
                tcpclient.Receive();

                switch (tcpclient.GetResolveType())
                {
                case TProtocol.RecvChatContent:
                    RecvChatContent chatcontentcmd = new RecvChatContent();
                    tcpclient.Dispatcher(chatcontentcmd);

                    Friend friend = new Friend()
                    {
                        _User = new EntityTUser()
                        {
                            uid = chatcontentcmd._Content._FromUID.ToString()
                        }
                    };

                    int    timestartindex = chatcontentcmd._Content._Text.Length - 19;
                    string dt             = chatcontentcmd._Content._Text.Substring(timestartindex, 19);

                    ChatMessage message = new ChatMessage()
                    {
                        _Content  = chatcontentcmd._Content._Text.Substring(0, timestartindex),
                        _RecvTime = DateTime.Parse(dt)
                    };

                    Friend findfriend = FriendCollector.FindFriend(friend);
                    if (findfriend != null)
                    {
                        if (findfriend._MessageMode == MessageMode.HasPop)
                        {
                            findfriend._Messages.Add(message);
                            TrafficMsg.PostMessage(int.Parse(findfriend._FrmHandle.ToString()), 500, 0, 0);
                        }
                        else
                        {
                            addMessageToFriend(findfriend, message);
                        }
                    }
                    else
                    {
                        friend._User        = UserMainWindow.GetFriendUser(friend._User.uid);
                        friend._Messages    = new List <ChatMessage>();
                        friend._MessageMode = MessageMode.None;
                        friend._Messages.Add(message);

                        FriendCollector.Add(friend);
                        TrafficMsg.PostMessage(int.Parse(UserMainWindow._FrmHandle.ToString()), 501, 0, 0);
                    }

                    break;

                case TProtocol.RecvOnlineMarkup:
                    tcpclient.SendToEndDevice(sendonlinecommand);
                    break;
                }
            }
            #endregion
        }