Exemple #1
0
 public static void Disconnect(ThreadType type, string username)
 {
     try
     {
         if (type == ThreadType.AnonymousThread)
         {
             Thread value;
             AnonymousThreads.TryRemove(username, out value);
             value.Join();
         }
         if (type == ThreadType.ClientThread)
         {
             Thread value;
             ClientThreads.TryRemove(username, out value);
             IMessagingClient client;
             Clients.TryRemove(username, out client);
             foreach (IMessagingClient sclient in Clients.Values)
             {
                 sclient.Alert(String.Format("{0} has diconnected", username), 3);
             }
             value.Join();
         }
     }
     catch (Exception e)
     {
         Guid guid = Guid.NewGuid();
         ConsoleUtilities.PrintCritical("A major server error has occured. Report to developer immediately. Writing to file {0}.error", guid);
         StreamWriter writer = new StreamWriter(String.Format("{0}.error", guid));
         writer.WriteLine(e.Message);
         foreach (var i in e.Data)
         {
             writer.WriteLine("{0}", i);
         }
     }
 }
Exemple #2
0
 public void start()
 {
     running  = true;
     listener = new TcpListener(IPAddress.Any, Port);
     listener.Start();
     while (running)
     {
         Socket client = listener.AcceptSocket();
         Console.WriteLine("Connected: " + client.RemoteEndPoint.ToString());
         Thread t = new Thread(() => serve(client));
         ClientThreads.Add(t);
         t.Start();
     }
     listener.Stop();
     listener = null;
 }
Exemple #3
0
 public void stop()
 {
     running = false;
     ClientThreads.ForEach(c => c.Abort());
 }