设个Timer1,三分钟触发一次。
Timer.OnTick()
{
Timer1.Enable=false;
//连接服务器接收数据
Timer1.Enable=true;}

解决方案 »

  1.   

    最关键的是我不明白要在什么地方接收,如果在Timer里可以接收当然好了,可是应该是实时接收才对的。即他一发过来就触发,象vb里的socket控件的arrive事件一样。
      

  2.   

    监听是不行的,因为是tcp客户端,有连接接收。我查一些资料也是循环的接收,while(true){
     .........
    }
    但是我不明白这样的死循环会不会有什么问题,我简单试了一下,发现有很耗资源,不知是不是我写错了。
    turnmissile(会翻跟头的导弹),可以给我一小段代码参考参考吗?
      

  3.   

    http://www.codeproject.com/csharp/c_sharp_remoting.asp?target=chatserver
      

  4.   

    采用异步,在委托中定义接收方法,有收到,会自动进入委托处理。
    加Timer计时3minute,后断开。
      

  5.   

    TcpClient或socket中有Asy为词头的一系列方法,如AsySend、AsyConnect、AsyRead等等吧,具体函数名记不清了,看看帮助吧,很好解决。
      

  6.   

    采用异步,在委托中定义接收方法,有收到,会自动进入委托处理。================================不知加那个委托,msdn里没查到资料。
      

  7.   

    问题1:
    你可以把监听线程放在page_Load事件中开始,这样只要你登陆就开始监听
    并接受对放发来的信息问题2:
      好象有个什么ConnectionTimeOut属性(不记得了,你查下)
      如果不行的话用Timer timer=new Timer();
                    timer.Interval=1000*60*3   //3 minutes
                    timer.Tick+=new EventHandler(timer_Tick);
                 void timer_Tick(object obj,EventArgs ea)
                   {...}                                           wish u good luck
                                                     Greatsft
      

  8.   

    应该是不能用监听的,TCP方式啊。
      

  9.   

    就是通过Socket的异步接收方法来接收数据,然后在委托中处理它。
    具体的使用方法可以参见Socket类的帮助文档。
      

  10.   

    我自已网络开发基础比较差。翻了点资料就上阵了,还有些地方没看明白。以下是我从msdn找的帮助文档中的关键代码,还是不太明白,大家帮忙看看,是不是用这个。注释是我加的。===================================================================
    //接收方法,静态成员
     private static void Receive(Socket client) {
            try {
                // Create the state object.
                StateObject state = new StateObject();
                state.workSocket = client;            // Begin receiving the data from the remote device.            client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback(ReceiveCallback), state); //new AsyncCallback(ReceiveCallback)调用委托,方法ReceiveCallBack;
            } catch (Exception e) {
               //..
            }
        }
    //以下是ReceiveCallback方法,“IAsyncResult ar”是什么意思?    private static void ReceiveCallback( IAsyncResult ar ) {
            try {
                // Retrieve the state object and the client socket 
                // from the asynchronous state object.
                StateObject state = (StateObject) ar.AsyncState;
                Socket client = state.workSocket;            // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);            if (bytesRead > 0) {
                    // There might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));                // Get the rest of the data.
                    client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
                        new AsyncCallback(ReceiveCallback), state);
                } else {
                    // All the data has arrived; put it in response.
                    if (state.sb.Length > 1) {
                        response = state.sb.ToString();
                    }
                    // Signal that all bytes have been received.
                    receiveDone.Set();
                }
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }  
      最重要的问题是,这个委托总是能够接收到不定时发过来的数据吗?
    只要一有数据发过来,ReceiveCallback方法就能触发吗?
      

  11.   

    TO: cchinasp(风和影的恋人)
    基本上是这样了,不过要注意的是当异步委托ReceiveCallback被触发后,需要再次调用BeginReceive(),还有可以指定接受字节数,利用它可以精确控制完整接受一个有长度描述的自定义报文。
      

  12.   

    else {
                    // All the data has arrived; put it in response.
                    if (state.sb.Length > 1) {
                        response = state.sb.ToString();
                    }
                    // Signal that all bytes have been received.
     
                   //在这里加上要调用的委托!!!!!!
                   
                   receiveDone.Set();
                 
                }