Esempio n. 1
0
        public static string msgShortSend;          // 发送给客户端一个数据包的信息

        static void Main(string[] args)
        {
            _databaseUserList     = UserLoading();     // 载入用户数据库
            _databaseActivityList = ActivityLoading(); // 载入活动数据库

            Socket      listener   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPEndPoint  localEP    = new IPEndPoint(ipHostInfo.AddressList[0], 8888);

            Console.WriteLine("本地IP地址和端口号为:{0}", localEP);
            try
            {
                listener.Bind(localEP);
                listener.Listen(10);
                while (true)
                {
                    //Console.WriteLine("等待客户端连接...");
                    listener.BeginAccept(AcceptCallBack, listener);
                    _flipFlop.WaitOne();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 2
0
        static userList UserLoading()  //载入用户信息
        {
            string   strList = "data\\namelist.txt";
            userList ust     = new userList();

            if (File.Exists(strList))
            {
                FileStream   myFs = new FileStream(strList, FileMode.Open);
                StreamReader mySr = new StreamReader(myFs);
                string       nameList = null, strtmp;
                while ((strtmp = mySr.ReadLine()) != null)
                {
                    nameList += strtmp;
                }
                mySr.Close();
                myFs.Close();
                string[] strtemp = nameList.Split(new char[] { '|' });
                for (int i = 0; i < strtemp.Length - 1; i++)
                {
                    string       result = null, strname = "data\\" + strtemp[i] + ".txt";
                    FileStream   myFs1 = new FileStream(strname, FileMode.Open);
                    StreamReader mySr1 = new StreamReader(myFs1);
                    while ((strtmp = mySr1.ReadLine()) != null)
                    {
                        result += strtmp;
                        string[] nList = result.Split(new char[] { '|' });
                        int      j     = 0;
                        ust.Add(nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++], nList[j++]);
                    }
                    mySr1.Close();
                    myFs1.Close();
                }
                return(ust);
            }
            else
            {
                return(ust);
            }
        }
Esempio n. 3
0
        private static void HandleLongDataFromClient() // 将客户端传来的数据报组织后获得的长字符串
        {
            msgLongReceive = msgLongReceive.Trim();
            Console.WriteLine("客户端传来的数据是" + msgLongReceive + "end");
            string       result = msgLongReceive;
            ActivityList alst   = ActivityLoading();
            userList     ulst   = UserLoading();
            char         index  = result[0];

            switch (index)
            {
            case '1':
                PostToMain(index + ulst.Rigest(result));
                break;

            case '2':
                PostToMain(index + ulst.Login(result));
                break;

            case '3':
                PostToMain(index + ulst.findFriend(result));
                break;

            case '4':
                string res = ulst.findMyActivity(result);
                PostToMain(index + alst.findMyActivity(res));
                break;

            case '5':
                ulst.PostEvent(result);
                PostToMain(index + alst.PostEvent(result));
                break;

            case '6':
                PostToMain(index + alst.searchEvent(result));
                break;

            case '7':
                PostToMain(index + ulst.searchFriend(result));
                break;

            case '8':
                PostToMain(index + ulst.Addfriend(result));
                break;

            case '9':
                PostToMain(index + ulst.finishActivity(result));
                break;

            case '0':
                result = alst.JoinActivity(result);
                PostToMain(index + ulst.JoinActivity(result));
                break;

            case 'a':
                PostToMain(index + alst.activityInfo(result));
                break;
            }
            ;
            msgLongReceive = "";
        }