Beispiel #1
0
        public void run()
        {
            IPEndPoint ipep = new IPEndPoint(IPAddress.Any, ChatSetting.port);

            Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            newsock.Bind(ipep);
            newsock.Listen(10);

            while (true)
            {
                Socket socket = newsock.Accept();
                Console.WriteLine("�����@�ӷs�s�u!");
                ChatSocket client = new ChatSocket(socket);
                try
                {
                    clientList.Add(client);
                    client.newListener(processMsgComeIn);
                }
                catch
                {
                }
            //                clientList.Remove(client);
            }
            //	  newsock.Close();
        }
 public void sendMsg()
 {
     if (user().Length == 0)
     {
         MessageBox.Show("�п�J�ϥΪ̦W��!");
         return;
     }
     if (client == null) {
         client = ChatSocket.connect(ChatSetting.serverIp);
         client.newListener(processMsgComeIn);
         client.send(user() + " : �s�ϥΪ̶i�J!");
         textBoxUser.Enabled = false;
     }
     if (msg().Length > 0) {
         client.send(user()+" : "+msg());
         textBoxMsg.Text = "";
     }
 }
Beispiel #3
0
        private void sendMsg()
        {
            if (user().Length == 0)//判斷目前使用者有沒有輸入名稱,若沒有則是沒有長度的,因此會跳出視窗要求請輸入使用者名稱(110.03.15)
            {
                MessageBox.Show("請輸入使用者名稱!");
                return;
            }
            if (client == null)
            {
                client = ChatSocket.connect(ChatSetting.serverIP);//這邊是開始連上server的ip(110.03.15)
                client.newlistener(processMsgComeIn);
                //ChatServer.cs檔案ChattingRoom類別裡的40行有解說(110.03.15)

                client.send("< " + user() + " >  新使用者進入!");
                textBoxUser.Enabled = false;
            }
            if (msg().Length > 0)
            {
                client.send(user() + " : " + msg());
                textBoxMsg.Text = "";
            }
        }