Пример #1
0
        //Thread listener;
        public void listen()
        {
            try
            {
                //��ȡ������ַ
                string hostName = Dns.GetHostName();
                IPAddress hostAddr = (IPAddress)Dns.GetHostByName(hostName).AddressList[0];
                string myAddr = hostAddr.ToString();

                socket = new RawSocket();
                socket.CreateAndBindSocket(myAddr);
                if (socket.ErrorOccurred)
                {
                    //MessageBox.Show("�������ִ���");
                    UpdateTBResult(ui, "�������ִ���\r\n");
                    return;
                }
                socket.KeepRunning = true;
                socket.PacketArrival += socket_PacketArrival;
                socket.Run();
            }
            catch// (Exception ex)
            {
                //Console.WriteLine(ex);
                //throw;
            }
            finally
            {
                //Console.Read();
                //socket.Shutdown();
            }
        }
Пример #2
0
        /// <summary>
        /// ���չ���Tcp��
        /// </summary>
        public void Receive()
        {
            try
            {
                //��ȡ������ַ
                string hostName = Dns.GetHostName();
                IPAddress hostAddr = (IPAddress)Dns.GetHostByName(hostName).AddressList[0];
                string myAddr = hostAddr.ToString();

                rSocket = new RawSocket();
                rSocket.CreateAndBindSocket(myAddr);
                if (rSocket.ErrorOccurred)
                {
                    UpdateTBResult(ui, "�����˿ڴ���");
                }
                rSocket.PacketArrival += TcpSyn_PacketArrival;
                rSocket.KeepRunning = true;
                rSocket.Run();
            }
            catch//(Exception ex)
            {
                //UpdateTBResult(ui, ex.Message.ToString());
            }
            finally
            {
                //rSocket.Shutdown();
            }
        }