【问题标题】:An address incompatible with the requested protocol was used?使用了与请求的协议不兼容的地址?
【发布时间】:2014-06-17 18:38:50
【问题描述】:

这是代码

Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("fe80::fc33:41d6:77f4:c8c7", 1000);

当我尝试连接此地址时,我得到“使用了与请求的协议不兼容的地址”异常。

【问题讨论】:

    标签: c# ipv6


    【解决方案1】:

    IPv6 链路专用地址在每个链路上都有效,因此您需要告诉系统要使用哪个链路。这通常通过将 % 和接口 ID 附加到地址来完成。使用全局地址通常更容易。

    【讨论】:

      【解决方案2】:

      在我的 FTP 服务器上上传文件夹时出现此错误:

      使用了与请求的协议不兼容的地址

      有时会成功上传,但有时会失败。

      namespace WindowsFormsApplication1
      {
          public partial class FormFtpLibraryExtensionDemo : Form
          {
              public FormFtpLibraryExtensionDemo()
              {
                  InitializeComponent();
              }
              public static FTP ftplib = null;
              public void ProgressEvent(System.IO.FileInfo File, long BytesTotal, long FileSize, long TotalBytesDirectorySent, long TotalBytesDirectory, long StartTickCount)
              {
                  if (this.InvokeRequired)
                  {
                      this.BeginInvoke(new MethodInvoker(delegate() { ProgressEvent(File, BytesTotal, FileSize, TotalBytesDirectorySent, TotalBytesDirectory, StartTickCount); }));
                      return;
                  }
      
                  TimeSpan elapsedSpan = new TimeSpan(DateTime.Now.Ticks - StartTickCount);
      
                  labelFilename.Text = "Filename: " + File.FullName;
                  labelCurrentSend.Text = "Current: " + (BytesTotal / 1024).ToString() + "/" + (FileSize / 1024).ToString() + " KB";
                  labelTotal.Text = "Total: " + (TotalBytesDirectorySent / 1024).ToString() + "/" + (TotalBytesDirectory / 1024).ToString() + " KB";
                  labelElapsed.Text = "Elapsed: " + string.Format("{0:D2}:{1:D2}:{2:D2}", elapsedSpan.Hours, elapsedSpan.Minutes, elapsedSpan.Seconds);
      
                  if (progressBar1.Value != (int)((BytesTotal * 100) / FileSize))
                      progressBar1.Value = (int)((BytesTotal * 100) / FileSize);
      
                  if (progressBar2.Value != (int)((TotalBytesDirectorySent * 100) / TotalBytesDirectory))
                      progressBar2.Value = (int)((TotalBytesDirectorySent * 100) / TotalBytesDirectory);
      
                  if ((new TimeSpan(DateTime.Now.Ticks - updateTime).TotalMilliseconds > 200) || (TotalBytesDirectorySent == TotalBytesDirectory))
                  {
                      updateTime = DateTime.Now.Ticks;
      
                      deltabytes = TotalBytesDirectorySent - deltabytes;
                      deltatime = elapsedSpan.Subtract(deltatime);
      
                      if (deltatime.Seconds > 0)
                      {
                          labelSpeed.Text = "Speed: " + (deltabytes / deltatime.Seconds / 1024).ToString() + " KB/s";
      
                          TimeSpan t = TimeSpan.FromSeconds((TotalBytesDirectory - deltabytes) / (deltabytes / deltatime.Seconds));
                          labelRemaining.Text = "Remaining: " + string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds);
                      }
                  }
      
                  if (BytesTotal == FileSize)
                  {
                      deltabytes = 0;
                      deltatime = new TimeSpan(0);
                  }
              }
      
              private long deltabytes = 0;
              private TimeSpan deltatime = new TimeSpan(0);
      
              private long updateTime = 0;
      
              private void buttonUpload_Click(object sender, EventArgs e)
              {
                  if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                  {
                      ftplib = new FTP(textBoxHost.Text, textBoxUsr.Text, textBoxPwd.Text);
      
                      ftplib.Connect();
      
                      new Thread(delegate()
                      {
                          ftplib.UploadFolderRecursively(folderBrowserDialog1.SelectedPath, ProgressEvent);
                      }).Start();
                  }
              }
      

      【讨论】:

      • 欢迎来到 Stack Overflow!如果您还有其他问题,请点击 按钮进行提问。
      猜你喜欢
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2022-12-12
      • 1970-01-01
      • 2018-12-31
      相关资源
      最近更新 更多