示例#1
0
        private void ServerIng()
        {
            while (run)
            {
                //服务接收处理
                Socket QS;
                QS = qTcpListener.AcceptSocket();
                Byte[] Stream = new Byte[1024];
                QS.Receive(Stream);
                string save = System.Text.Encoding.UTF8.GetString(Stream);
                CheckOutDate(save);
                switch (parameter[0])
                {
                case "1":                          //该用户上线
                    TrafficMsg.PostMessage(ShareDate.MainFormHand, 500, 1, 0);
                    Login.SendMsgToGetOnlineInf(); //获取新的在线用户列表
                    System.Threading.Thread ShowOnline = new Thread(new ThreadStart(ShowInfWin));
                    ShowOnline.Start();
                    break;

                case "2":                                                      //接收到来自用户的消息;格式为(标识;源用户;消息内容)
                    TrafficMsg.PostMessage(ShareDate.MainFormHand, 500, 2, 0); //发送播放声音提示消息
                    System.Threading.Thread SM = new Thread(new ThreadStart(ShowMsg));
                    SM.Start();                                                //创建聊天窗口
                    break;

                default:                        //发送错误参数
                    break;
                }
                QS.Close();
            }
        }
示例#2
0
        private void QQServerIng()
        {
            try
            {
                while (ServerRun)
                {
                    Socket QS;
                    QS = qTcpListener.AcceptSocket();
                    string RemoteEndPoint = QS.RemoteEndPoint.ToString();
                    Byte[] Stream         = new Byte[1024];
                    QS.Receive(Stream);
                    string save    = System.Text.Encoding.UTF8.GetString(Stream);
                    string Sendmsg = "";
                    CheckOutDate(save);
                    switch (parameter[0])
                    {
                    case "1":    //验证用户登陆消息
                        if (opDate.qUserLogin(parameter[1], parameter[2]))
                        {
                            Sendmsg = "1";
                            XmlOperate.AddOnlineUser(parameter[1], RemoteEndPoint);
                        }
                        else
                        {
                            Sendmsg = "0";
                        }
                        SendMsg(QS, Sendmsg);
                        break;

                    case "2":    //发送好友分组资料请求
                        XmlOperate friend  = new XmlOperate();
                        string     FileUrl = "";
                        while ((FileUrl = friend.MakeFriendXml(parameter[1])) == "-1")
                        {
                        }
                        SendFile(QS, FileUrl);
                        XmlFileOp.DelThisFile(FileUrl);
                        break;

                    case "3":    //发送群组资料请求
                        break;

                    case "4":    //发送查找结果
                        break;

                    case "5":    //注册用户
                        break;

                    case "6":    //请求在线用户列表
                        SendFile(QS, "onlineinf\\onLine.xml");
                        break;

                    case "7":                            //添加好友 消息格式为:类型号;好友拥有者,好友号码
                        Sendmsg = opDate.AddFriend(parameter[1].Trim(), parameter[2].Trim());
                        SendMsg(QS, Sendmsg);
                        break;

                    default:    //发送错误参数
                        break;
                    }
                    QS.Close();
                }
            }
            catch { }
        }