TcpClient 和 UdpClient 抛出错误 [英] TcpClient and UdpClient throwing errors

查看:70
本文介绍了TcpClient 和 UdpClient 抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行 Windows 7 x64 和 VS2012 U1 并使用 .Net 4 的两个系统上,如果我调用 UdpClient 或 TcpClient,我会收到错误提供的参数无效".

On two systems running Windows 7 x64 and VS2012 U1 and using .Net 4 I get the error "An invalid argument was supplied" if I call UdpClient or TcpClient.

我已经尝试了多个端口,并且已经验证这些端口尚未绑定,但我每次都遇到相同的错误.

I've tried a number of ports and I've verified that the ports are not already bound but I get the same error every time.

我也试过以提升的权限运行代码,但无济于事.

I've also tried running the code with elevated privileges to no avail.

测试代码:

try
        {
            using (UdpClient client = new UdpClient(new IPEndPoint(IPAddress.Any, 123)))
            {
                Console.WriteLine("Port is open");
            }
        }
        catch (SocketException error)
        {
            Console.WriteLine("Error:\n{0}", error.Message);
        }

错误输出:

System.Net.Sockets.SocketException was unhandled
  HResult=-2147467259
  Message=An invalid argument was supplied
  Source=System
  ErrorCode=10022
  NativeErrorCode=10022
  StackTrace:
       at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
       at System.Net.Sockets.UdpClient..ctor(IPEndPoint localEP)
       at GetNTPTime.Program.Main(String[] args) in z:\My Documents\Dropbox\Dev\C#\_Example\GetNTPTime\GetNTPTime\Program.cs:line 15
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

请注意,如果我简单地调用 UdpClient client = new UdpClient();

As a note I get the same error if I simply call UdpClient client = new UdpClient();

推荐答案

问题是我的代码是从 Dropbox 文件夹执行的,并且由于某种原因导致了问题,即使 Dropbox 没有在系统上运行时间.如果我将代码库移到桌面并运行它,一切正常.

The issue was that my code was being executed from a Dropbox folder and for some reason that was causing the issues even if Dropbox wasn't running on the system at the time. If I moved the code base to the desktop and run it everything works.

我做了更多研究,发现问题不是 Dropbox 而是 Cloudfogger,如果我关闭 Cloudfogger 一切正常.

I did some more research and I've found that it is not Dropbox causing the issue but Cloudfogger, if I close Cloudfogger everything works.

这篇关于TcpClient 和 UdpClient 抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆