为什么执行到
byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
这里的时候就没有相应了呢?

解决方案 »

  1.   

    m_Socket = new TcpClient( "61.139.72.194"  , m_nPort ) ; 
    //MessageBox.Show("成功连接到服务器!");
    string temp = this.sendMsg("login#"+user_id+"#"+machine_id+"#"+user_pwd+"%");//收发函数
    /// <summary>
    /// 向服务器传输信息,同时收到服务器返回的信息
    /// </summary>
    private string sendMsg( string msg ) 
    {
    NetworkStream stream = null ;
    Byte[] data = System.Text.Encoding.ASCII.GetBytes( msg );         
    try
    {
    Debug.Write(msg);
    stream = m_Socket.GetStream();
    stream.Write(data, 0, data.Length);
    stream.Flush() ;
    }
    catch( SocketException e )
    {
    Debug.Write( "SocketException: " + e.ToString() );
    return null ;
    }

    Thread.Sleep( 300 ) ; Byte[] data1 = new byte[128] ;
     
    try
    {
    stream.Read( data1 , 0 , data1.Length ) ;
    string rcv = System.Text.Encoding.ASCII.GetString( data1 ) ;
    stream.Flush();
    return rcv.ToString().Trim();
    }
    catch( Exception ex )
    {
    Debug.Write( "SocketException: " + ex.Message.ToString() );
    return null ;
    }
    }
      

  2.   

    这是tcp的,希望对你有帮助……
      

  3.   

    你这样看来是不可以,因为UDP你发送完后就丢失了;你需要写两个程序,一个先接着;
    然后另一个再发;