예제 #1
0
        public CommandHandler(ServerHandler serverConnection, FormChatWindow chatWindow)
        {
            this.serverConnection              = serverConnection;
            this.chatWindow                    = chatWindow;
            chatWindow.EventClientConnect     += OnEventClientConnect;
            chatWindow.EventClientDisconnect  += OnEventClientDisconnect;
            chatWindow.EventClientSendMessage += OnEvenClientSendMessage;

            serverConnection.EventClientRecieveMessage += OnEventClientRecieveMessage;
        }
예제 #2
0
        public FormChatWindow(Form parentForm, TcpClient server, string clientName)
        {
            InitializeComponent();

            this.clientName    = clientName;
            this.parentForm    = parentForm;
            this.serverHandler = new ServerHandler(server, this);
            OnEventClientConnect(new ServerMessageEventArgs());
            chatTextBox.ReadOnly = true;
        }
예제 #3
0
        static void Main(string[] args)
        {
            TcpClient client = null;

            try
            {
                //LocalHost에 지정 포트로 TCP Connection을 생성하고 데이터를 송수신 하기
                //위한 스트림을 얻는다.
                client = new TcpClient();
                client.Connect("192.168.0.18", 5001);

                NetworkStream stream = client.GetStream();
                Encoding      encode = System.Text.Encoding.GetEncoding("euc-kr");
                StreamReader  reader = new StreamReader(stream, encode);
                StreamWriter  writer = new StreamWriter(stream, encode)
                {
                    AutoFlush = true
                };

                //글읽는 부분을 ServerHandler에서 처리하도록 쓰레드로 만든다.
                ServerHandler serverHandler = new ServerHandler(reader);
                Thread        t             = new Thread(new ThreadStart(serverHandler.Chat));
                t.Start();

                string dataToSend = Console.ReadLine();

                while (true)
                {
                    writer.WriteLine(dataToSend);
                    if (dataToSend.IndexOf("<EOF>") > -1)
                    {
                        break;
                    }

                    dataToSend = Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                client.Close();
                client = null;
            }
        }