Example #1
0
    static void Main(string[] args)
    {
        DateTime now = DateTime.Now;
        Console.WriteLine("[" + now.ToString("tthh:mm:ss") + "]");
        TcpListener listener = null;
        bool Start_Service = false;
        try
        {
            //IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
            //IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
            IPAddress ipAddress = IPAddress.Any;
            listener = new TcpListener(ipAddress, 3000);
            listener.Start();
            Console.WriteLine("** ChatServer **");
            Console.WriteLine("1. 대기중입니다.");
            while (!Start_Service)
            {
                Socket socket = listener.AcceptSocket();
                Console.WriteLine("[+접속클라이언트]:" + socket.RemoteEndPoint);
                if (socket.Connected)
                {
                    //ChatSupporter 스레드 생성
                    ChatSupporter cs = new ChatSupporter(socket);

                    //ChatSupporter room에 저장
                    room.AddChatSupporter(cs);
                }
            }
        }
        catch
        {
            Console.WriteLine("서버 생성 도중 에러");
            return;
        }
    }
Example #2
0
 public void AddChatSupporter(ChatSupporter client)
 {
     this.SendAll(client.ToString() + "입장했습니다.");
     lock (list.SyncRoot)
     {
         list.Add(client);
     }
 }
Example #3
0
 public void RemoveChatSupporter(ChatSupporter client)
 {
     lock (list.SyncRoot)
     {
         list.Remove(client);
         this.SendAll(client.ToString() + "퇴장했습니다.");
         Console.WriteLine("[-퇴장클라이언트]:" + client.ToString());
         client.closeConnection();
     }
 }