예제 #1
0
 private void DisconnectHandler(TCPBase <SERV, CLNT> client)
 {
     if (DisconnectionHandler != null)
     {
         DisconnectionHandler(client);
     }
 }
        public TCPBase InitTCP_IPArgs(bool isServer = true, string ArgsTableName = null)
        {
            TCPBase tCPBase = null;

            if (!isServer)
            {
                TCPFactoryClient tCPFactoryClient = (ArgsTableName != null) ? new TCPFactoryClient(ArgsTableName) : new TCPFactoryClient();
                tCPFactoryClient.Route = ClientRouteMessage;
                tCPFactoryClient.Connect();
                return(tCPFactoryClient);
            }
            TCPFactoryServer tCPFactoryServer = (ArgsTableName != null) ? new TCPFactoryServer(ArgsTableName) : new TCPFactoryServer();

            tCPFactoryServer.Route = ServerRouteMessage;
            tCPFactoryServer.Boot();
            return(tCPFactoryServer);
        }
예제 #3
0
        public void RouteMessage(int nIndex_Client, byte[] byts)
        {
            switch (TCPBase.FetchMSGMark(byts))
            {
            case REMOTE_DOWNLOAD:
                DownloadMovie(); break;

            case REMOTE_DELETEFILE:
                DeleteMovie(); break;

            case REMOTE_MULTIDOWNLOAD:
                MultiDownload(nIndex_Client, byts); break;

            case REMOTE_QUERY_AVAILABLE_MOVIE_NAMES:
                Query_Available_Movie_Names(nIndex_Client, byts);
                break;
            }
        }
예제 #4
0
 void ClientDiconnect(TCPBase <ServerMessage, ClientMessage> client)
 {
     godsCount--;
     UpdateText();
 }
예제 #5
0
        private void Query_Available_Movie_Names(int nIndex_Client, byte[] byts)
        {
            StringBuilder sb            = new StringBuilder();
            String        strFolderPath = this.ProvideString(byts, MARKPOSITION, (int)TCPBase.FetchDataLenByts(byts));

            String []     strArrX       = File.ReadAllLines("map", Encoding.Default);
            List <String> list          = strArrX.ToList();
            int           nHowManyItems = 0;

            if (list.Contains(strFolderPath.ToLower()))
            {
                int n = list.IndexOf(strFolderPath.ToLower());
                strFolderPath = list[n + 1];
            }
            else
            {
                return;
            }
            String[] strArr = null;
            try
            {
                strArr = Directory.GetFiles(strFolderPath);
            }
            catch
            {
                R.mainPage.Invoke(R.mainPage.DoRefreshLayout, MainPage.CODE_LBL_STATUS, "未能找到E盘");
                Send(nIndex_Client, REMOTE_QUERY_AVAILABLE_MOVIE_NAMES, en.GetBytes("NG"));
                KillClientThread(nIndex_Client);
                return;
            }
            for (int i = 0; i < strArr.Length; i++)
            {
                string ext = Path.GetExtension(strArr[i]).ToLower();

                if (ext.Contains("mp4"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("mkv"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("rmvb"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("avi"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("flv"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("f4v"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("mov"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
                else if (ext.Contains("wmv"))
                {
                    sb.AppendFormat("{0}^", Path.GetFileName(strArr[i]));
                }
            }
            if (sb.Length > 1)
            {
                sb.Remove(sb.Length - 1, 1);
                string[] strTest = sb.ToString().Split('^');
                nHowManyItems = strTest.Length;
                Send(nIndex_Client, REMOTE_QUERY_AVAILABLE_MOVIE_NAMES, en.GetBytes(sb.ToString()));
            }
            else
            {
                Send(nIndex_Client, REMOTE_QUERY_AVAILABLE_MOVIE_NAMES, en.GetBytes("NG"));
            }

            KillClientThread(nIndex_Client);
            R.mainPage.Invoke(R.mainPage.DoRefreshLayout, MainPage.CODE_LBL_STATUS, String.Format("已经发送{0}条数据", nHowManyItems));
        }