NATUPNPlib.UPnPNATClass upnpnat = new NATUPNPlib.UPnPNATClass();NATUPNPlib.IStaticPortMapPingCollection mapPings = upnpnat.StaticPortMapPingCollection;mapPings.Add(8000,"TCP",8000,"192.168.1.100",true,"Local Web Server");
但它不起作用!,例外情况如下:
Object reference not set to an instance of an object.
有人可以帮我吗?
这就是我正在做的事:http://pietschsoft.com/post/2009/02/05/NET-Framework-Communicate-through-NAT-Router-via-UPnP.aspx
解决方法 您需要将映射设置为新实例:例如:
var mapPings = new List<MapPing>();
然后你可以打电话:
mapPings.Add(8000,"Local Web Server");
从你的编辑:
upnpnat.StaticPortMapPingCollection; // this is your problem.
该集合将返回null.因此您无法添加到集合中.
你可能必须这样做:
NATUPNPlib.IStaticPortMapPingCollection mapPings = new StaticPortMapPingCollection();
来自Codesleuth的评论:
总结I belIEve the answer is that his router isn’t configured as a UPnP gateway,or that he has no permissions. The StaticPortMapPingCollection is null if either of those cases are true. I suggest you edit this into your answer as you’ve got the right reason for the error anyway. Checking for null first is the only way to deal with the error
以上是内存溢出为你收集整理的无法在我的c#应用程序中添加静态端口映射全部内容,希望文章能够帮你解决无法在我的c#应用程序中添加静态端口映射所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)