Ejemplo n.º 1
0
 // private void AsynServerListen(IAsyncResult ar){
 //     ListenSocket = (Socket) ar.AsyncState;
 //     FileSocket = ListenSocket.EndAccept(ar);
 // }
 private void ServerListen()
 {
     //State.Listen = true;
     Console.WriteLine("Waiting...");
     while (!Config.SHUTDOWN)
     {
         try {
             //ListenSocket.BeginAccept(new AsyncCallback(AsynServerListen),ListenSocket);
             FileSocket = ListenSocket.Accept();
             //////////////!!!!!!!!!!!!!!!
             //Config.SHUTDOWN = true;
             Debug.Log("Server Accept");
             //////////////!!!!!!!!!!!!!!!
         }
         catch (Exception e) {
             if (Config.SHUTDOWN)
             {
                 break;
             }
             else
             {
                 Console.WriteLine(e.ToString());
             }
         }
         try
         {
             ThreadStruct AS      = new ThreadStruct();
             IPAddress    Address = getAddress(FileSocket);
             Dict.Add(((IPEndPoint)FileSocket.RemoteEndPoint).Address, AS);
             //Dict.Add(((IPEndPoint)FileSocket.RemoteEndPoint).Address,FileSocket);
             Dict[Address].ThreadSocket       = FileSocket;
             Dict[Address].ThreadState.Listen = true;
             Dict[Address].usergroup          = UserGroup.Stranger;
             Dict[Address].filepath           = "";
             log("Client" + " " + FileSocket.RemoteEndPoint + " " + "connected.");
             MessageThread = new Thread(new ParameterizedThreadStart(MessageTransport));
             Dict[Address].MessageThread = MessageThread;
             MessageThread.Start(FileSocket);//FileSocket
         }
         catch (Exception e)
         {
             CloFunc.Errorinfo("Listening Fail :\n" + e.ToString());
             //same ip adress try to connect twice is illegal
         }
     }
 }
Ejemplo n.º 2
0
        public static void Add(Action staticMethod, string description, int minutes)
        {
            if (actions == null)
            {
                actions = new List <ThreadStruct>();
            }

            var name   = staticMethod.Method.DeclaringType.FullName;
            var thread = new ThreadStruct(staticMethod, description, minutes);
            var track  = Diagnostic.TrackObject(thread);

            if (!actions.Where(t => t.name == name).Any())
            {
                actions.Add(thread);

                Diagnostic.Debug(LOG, track, $"Added {thread.name} action in the thread. Details: {thread.description}.");
            }
            else
            {
                var index = actions.FindIndex(t => t.name == name);
                actions[index] = thread;
                Diagnostic.Debug(LOG, track, $"Updated {thread.name} action in the thread. Details: {thread.description}.");
            }
        }