|
-
Nov 29th, 2011, 04:10 PM
#1
Thread Starter
Hyperactive Member
VB.NET and UPnP?
working on an FPS and i'm getting stuck when it comes to making it "EASY" for people to connect.
it seems that to have their router automatically open a port (?) i will have to use UPnP.
(the ports i need to open are a simple 45000 and 45001.)
does anyone have an example of how to use UPnP in VB.NET 2010?
is it used to open ports (such as UDP) or is it a separate protocol?
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Nov 30th, 2011, 01:37 AM
#2
Re: VB.NET and UPnP?
There is a way to do it, but you need .NET 3.5 I believe to use the COM object properly. Since you're using 2010, that shouldn't be an issue.
You need to add a reference to NATUPnP as a COM object in Visual Studio. I use this class to handle my UPnP options:
Code:
Public Class UPnP
Implements IDisposable
Private upnpnat As NATUPNPLib.UPnPNAT
Private staticMapping As NATUPNPLib.IStaticPortMappingCollection
Private dynamicMapping As NATUPNPLib.IDynamicPortMappingCollection
Private staticEnabled As Boolean = True
Private dynamicEnabled As Boolean = True
''' <summary>
''' The different supported protocols
''' </summary>
''' <remarks></remarks>
Public Enum Protocol
''' <summary>
''' Transmission Control Protocol
''' </summary>
''' <remarks></remarks>
TCP
''' <summary>
''' User Datagram Protocol
''' </summary>
''' <remarks></remarks>
UDP
End Enum
''' <summary>
''' Returns if UPnP is enabled.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property UPnPEnabled As Boolean
Get
Return staticEnabled = True OrElse dynamicEnabled = True
End Get
End Property
''' <summary>
''' The UPnP Managed Class
''' </summary>
''' <remarks></remarks>
Public Sub New()
'Create the new NAT Class
upnpnat = New NATUPNPLib.UPnPNAT
'generate the static mappings
Me.GetStaticMappings()
Me.GetDynamicMappings()
End Sub
''' <summary>
''' Returns all static port mappings
''' </summary>
''' <remarks></remarks>
Private Sub GetStaticMappings()
Try
staticMapping = upnpnat.StaticPortMappingCollection()
Catch ex As NotImplementedException
staticEnabled = False
End Try
End Sub
''' <summary>
''' Returns all dynamic port mappings
''' </summary>
''' <remarks></remarks>
Private Sub GetDynamicMappings()
Try
dynamicMapping = upnpnat.DynamicPortMappingCollection()
Catch ex As NotImplementedException
dynamicEnabled = False
End Try
End Sub
''' <summary>
''' Adds a port mapping to the UPnP enabled device.
''' </summary>
''' <param name="localIP">The local IP address to map to.</param>
''' <param name="Port">The port to forward.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <param name="desc">A small description of the port.</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when any of the supplied arguments are invalid.</exception>
''' <remarks></remarks>
Public Sub Add(ByVal localIP As String, ByVal Port As Integer, ByVal prot As Protocol, ByVal desc As String)
' Begin utilizing
If Exists(Port, prot) Then Throw New ArgumentException("This mapping already exists!", "Port;prot")
' Check
If Not IsPrivateIP(localIP) Then Throw New ArgumentException("This is not a local IP address!", "localIP")
' Final check!
If Not staticEnabled Then Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
' Okay, continue on
staticMapping.Add(Port, prot.ToString(), Port, localIP, True, desc)
End Sub
''' <summary>
''' Removes a port mapping from the UPnP enabled device.
''' </summary>
''' <param name="Port">The port to remove.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when the port [or protocol] is invalid.</exception>
''' <remarks></remarks>
Public Sub Remove(ByVal Port As Integer, ByVal Prot As Protocol)
' Begin utilizing
If Not Exists(Port, Prot) Then Throw New ArgumentException("This mapping doesn't exist!", "Port;prot")
' Final check!
If Not staticEnabled Then Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
' Okay, continue on
staticMapping.Remove(Port, Prot.ToString)
End Sub
''' <summary>
''' Checks to see if a port exists in the mapping.
''' </summary>
''' <param name="Port">The port to check.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when the port [or protocol] is invalid.</exception>
''' <remarks></remarks>
Public Function Exists(ByVal Port As Integer, ByVal Prot As Protocol) As Boolean
' Final check!
If Not staticEnabled Then Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
' Begin checking
For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping
' Compare
If mapping.ExternalPort.Equals(Port) AndAlso mapping.Protocol.ToString.Equals(Prot.ToString) Then Return True
Next
'Nothing!
Return False
End Function
''' <summary>
''' Attempts to locate the local IP address of this computer.
''' </summary>
''' <returns>String</returns>
''' <remarks></remarks>
Public Shared Function LocalIP() As String
Dim IPList As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each IPaddress In IPList.AddressList
If (IPaddress.AddressFamily = Sockets.AddressFamily.InterNetwork) AndAlso IsPrivateIP(IPaddress.ToString()) Then
Return IPaddress.ToString
End If
Next
Return String.Empty
End Function
''' <summary>
''' Checks to see if an IP address is a local IP address.
''' </summary>
''' <param name="CheckIP">The IP address to check.</param>
''' <returns>Boolean</returns>
''' <remarks></remarks>
Private Shared Function IsPrivateIP(ByVal CheckIP As String) As Boolean
Dim Quad1, Quad2 As Integer
Quad1 = CInt(CheckIP.Substring(0, CheckIP.IndexOf(".")))
Quad2 = CInt(CheckIP.Substring(CheckIP.IndexOf(".") + 1).Substring(0, CheckIP.IndexOf(".")))
Select Case Quad1
Case 10
Return True
Case 172
If Quad2 >= 16 And Quad2 <= 31 Then Return True
Case 192
If Quad2 = 168 Then Return True
End Select
Return False
End Function
''' <summary>
''' Disposes of the UPnP class
''' </summary>
''' <param name="disposing">True or False makes no difference.</param>
''' <remarks></remarks>
Protected Overridable Sub Dispose(disposing As Boolean)
Marshal.ReleaseComObject(staticMapping)
Marshal.ReleaseComObject(dynamicMapping)
Marshal.ReleaseComObject(upnpnat)
End Sub
''' <summary>
''' Dispose!
''' </summary>
''' <remarks></remarks>
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
''' <summary>
''' Prints out some debugging information to use.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function Print() As List(Of String)
' Return list
Dim L As New List(Of String)
' Loop through all the data after a check
If staticEnabled Then
For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping
' Add some initial data
L.Add("--------------------------------------")
'Grab the rest
L.Add(String.Format("IP: {0}", mapping.InternalClient))
L.Add(String.Format("Port: {0}", mapping.InternalPort))
L.Add(String.Format("Description: {0}", mapping.Description))
Next
End If
'Finisher
L.Add("--------------------------------------")
' Give it back
Return L
End Function
End Class
I should probably put this up on the Code bank somewhere...
-
Nov 30th, 2011, 01:48 AM
#3
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Thanks formlesstree4 
is it forward compatible with .net 4.0?
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Nov 30th, 2011, 02:53 AM
#4
Re: VB.NET and UPnP?
 Originally Posted by Waxy
Thanks formlesstree4
is it forward compatible with .net 4.0?
I wrote the class in .NET 4 so I would like to think so!
-
Nov 30th, 2011, 03:13 AM
#5
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Ok, i THINK i understand this.
So UPnP is used to map ports on UPnP enabled devices.
so, if i'm using this right, then...
Code:
Function This() As Boolean
Dim MyUPnPMap As New ClientUPnP
If MyUPnPMap.Exists(45000, ClientUPnP.Protocol.UDP) Then
Return False 'already in use
Else
MyUPnPMap.Add(ClientUPnP.LocalIP, 45000, ClientUPnP.Protocol.UDP, "Dust Client")
Return True 'successfully added
End If
End Function
(i hate being such a Network Programming noob. it took me forever just to get UDP over the internet! ugh.)
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Nov 30th, 2011, 03:31 AM
#6
Re: VB.NET and UPnP?
That should work; make sure LocalIP is proper though before utilizing it; it's a guesswork system I use inside the class.
-
Nov 30th, 2011, 04:47 AM
#7
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Thank you very much, Formless
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Dec 21st, 2011, 12:57 AM
#8
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Revising an old thread.
I've been in hiatus for a while.
i've added it to my project. the client APPEARS to be working correctly, but i'm getting a crash in the server (no, no client working on current machine, just the server by itself)
it's the same machine i was testing the client on.
here's the error:
Code:
Irrlicht Engine version 1.8.0-alpha
Microsoft Windows 7 Ultimate Edition (Build 7600)
Irrlicht Lime version 0.9.1
>> CLOSE PORT....
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> OPEN PORT...
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> Port not in use. Adding...
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> UPNP ADD: Sub Add(LocalIP=192.168.1.13, Port=45000, prot=UDP, desc=Dust Server)
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> passed If Exists(45000, 1)
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> passed IF NOT IsPrivateIP(192.168.1.13)
>> passed 'If Not staticEnabled'
>> adding UPNP with:
>> staticMapping.Add(45000, UDP, 45000, 192.168.1.13, True,Dust Server)
>> ---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 128
>> Starting Virtual Grapics Device...
suggestions?
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Dec 21st, 2011, 01:41 AM
#9
Re: VB.NET and UPnP?
I have no idea what that error actually is. Perhaps the device is rejecting the mapping? I've not really seen such an error before.
-
Dec 21st, 2011, 08:52 PM
#10
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
K. i'll keep up the research.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 3rd, 2012, 02:58 AM
#11
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Still trying to find the bug. 
ANY AND ALL ideas (even stupid ones) are welcome.
LINK TO ERROR OUTPUT (image)
FIRST CALL IN MODULE2.BAS:
OpenPort Code:
Public Sub Main()
MyPath = Application.StartupPath
'being PNP
' msg("attempting ClosePort")
' ClosePort(MyPort)
' msg("attempting OpenPort")
OpenPort(MyPort)
ServerGameInfo.GameType = eGameType.FFA
ServerGameInfo.Gamestate = eGameState.WAITING
ServerSettings.MaxPing = 500
OPEN PORT FUNCTION IN MODULE2.BAS:
OpenPort Code:
Function OpenPort(ByVal SubjectPort As Integer) As Boolean
Dim MyUPnPMap As New ServerUPnP
msg("OPEN PORT...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
msg(" TCP...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
msg(" mapping....")
If MyUPnPMap.Exists(SubjectPort, ServerUPnP.Protocol.TCP) Then
msg(" EXISTS=True; RETURNING FALSE!")
Return False 'already in use
Else
msg(" Port not in use. Adding...")
MyUPnPMap.Add(ServerUPnP.LocalIP, SubjectPort, ServerUPnP.Protocol.TCP, "Dust Server")
Return True 'successfully added
End If
'msg(" UDP...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
'If MyUPnPMap.Exists(SubjectPort, ServerUPnP.Protocol.UDP) Then
' msg(" EXISTS=True; RETURNING FALSE!")
' Return False 'already in use
'Else
' msg(" Port not in use. Adding...")
' MyUPnPMap.Add(ServerUPnP.LocalIP, SubjectPort, ServerUPnP.Protocol.UDP, "Dust Server")
' Return True 'successfully added
'End If
End Function
UPNP CLASS:
staticMapping.Add(Port, prot.ToString(), Port, localIP, True, desc) Code:
Imports System.Net
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class ServerUPnP
Implements IDisposable
Private upnpnat As NATUPNPLib.UPnPNAT
Private staticMapping As NATUPNPLib.IStaticPortMappingCollection
Private dynamicMapping As NATUPNPLib.IDynamicPortMappingCollection
Private staticEnabled As Boolean = True
Private dynamicEnabled As Boolean = True
''' <summary>
''' The different supported protocols
''' </summary>
''' <remarks></remarks>
Public Enum Protocol
''' <summary>
''' Transmission Control Protocol
''' </summary>
''' <remarks></remarks>
TCP
''' <summary>
''' User Datagram Protocol
''' </summary>
''' <remarks></remarks>
UDP
End Enum
''' <summary>
''' Returns if UPnP is enabled.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property UPnPEnabled As Boolean
Get
Return staticEnabled = True OrElse dynamicEnabled = True
End Get
End Property
''' <summary>
''' The UPnP Managed Class
''' </summary>
''' <remarks></remarks>
Public Sub New()
'Create the new NAT Class
upnpnat = New NATUPNPLib.UPnPNAT
'generate the static mappings
Me.GetStaticMappings()
Me.GetDynamicMappings()
End Sub
''' <summary>
''' Returns all static port mappings
''' </summary>
''' <remarks></remarks>
Private Sub GetStaticMappings()
Try
staticMapping = upnpnat.StaticPortMappingCollection()
Catch ex As NotImplementedException
staticEnabled = False
End Try
End Sub
''' <summary>
''' Returns all dynamic port mappings
''' </summary>
''' <remarks></remarks>
Private Sub GetDynamicMappings()
Try
dynamicMapping = upnpnat.DynamicPortMappingCollection()
Catch ex As NotImplementedException
dynamicEnabled = False
End Try
End Sub
''' <summary>
''' Adds a port mapping to the UPnP enabled device.
''' </summary>
''' <param name="localIP">The local IP address to map to.</param>
''' <param name="Port">The port to forward.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <param name="desc">A small description of the port.</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when any of the supplied arguments are invalid.</exception>
''' <remarks></remarks>
Public Sub Add(ByVal localIP As String, ByVal Port As Integer, ByVal prot As Protocol, ByVal desc As String)
msg(" BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=" & localIP & ", Port=" & Port.ToString & ", prot=" & prot.ToString & ", desc=" & desc & ")")
' Begin utilizing
If Exists(Port, prot) Then
msg(" EXISTS = TRUE. THROWING EXCEPTION: 'This mapping already exists!', " & Port.ToString & ";" & prot.ToString)
Throw New ArgumentException("This mapping already exists!", "Port;prot")
'Remove(Port, Protocol.UDP)
Else
msg(" passed If Exists(" & Port.ToString & ", " & prot & ")")
End If
' Check
If Not IsPrivateIP(localIP) Then
msg(" IsPrivateIP(LocalIp) = False. THROWING EXCEPTION: 'This is not a local IP address!'," & localIP)
Throw New ArgumentException("This is not a local IP address!", "localIP")
Else
msg(" passed IF NOT IsPrivateIP(" & localIP & ")")
End If
' Final check!
If Not staticEnabled Then
msg(" staticEnabled=FALSE - THROWING EXCEPTION: 'UPnP is not enabled, or there was an error with UPnP Initialization.'")
Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
Else
msg(" passed 'If Not staticEnabled'")
End If
msg(" adding UPNP with:")
msg(" staticMapping.Add(" & Port.ToString & ", " & prot.ToString() & ", " & Port.ToString & ", " & localIP & ", True," & desc & ")")
' Okay, continue on
Try
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
'This is the line 132 in the output display. (+ 2 lines for edit in forum box. )
staticMapping.Add(Port, prot.ToString(), Port, localIP, True, desc)
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
Catch ex As Exception
MsgBox(ex.ToString)
msg(" ---ERROR:" & ex.ToString)
End Try
End Sub
''' <summary>
''' Removes a port mapping from the UPnP enabled device.
''' </summary>
''' <param name="Port">The port to remove.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when the port [or protocol] is invalid.</exception>
''' <remarks></remarks>
Public Sub Remove(ByVal Port As Integer, ByVal Prot As Protocol)
Try
' Begin utilizing
If Not Exists(Port, Prot) Then
'Throw New ArgumentException("This mapping doesn't exist!", "Port;prot")
Exit Sub
End If
' Final check!
If Not staticEnabled Then Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
Catch
End Try
' Okay, continue on
staticMapping.Remove(Port, Prot.ToString)
End Sub
''' <summary>
''' Checks to see if a port exists in the mapping.
''' </summary>
''' <param name="Port">The port to check.</param>
''' <param name="prot">The protocol of the port [TCP/UDP]</param>
''' <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
''' <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
''' <exception cref="ArgumentException">This exception is thrown when the port [or protocol] is invalid.</exception>
''' <remarks></remarks>
Public Function Exists(ByVal Port As Integer, ByVal Prot As Protocol) As Boolean
msg("Checking Function Exists(port=" & Port.ToString & ", Prot=" & Prot.ToString & ") ....")
' Final check!
If Not staticEnabled Then
msg(" staticEnabled = False")
Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
End If
' Begin checking
For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping
' Compare
If mapping.ExternalPort.Equals(Port) AndAlso mapping.Protocol.ToString.Equals(Prot.ToString) Then
msg(" ' Begin Checking For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping' returned TRUE")
Return True
End If
Next
msg(" Mapping For-Each check passed.")
msg(" Returning FALSE")
msg(" ")
'Nothing!
Return False
End Function
''' <summary>
''' Attempts to locate the local IP address of this computer.
''' </summary>
''' <returns>String</returns>
''' <remarks></remarks>
Public Shared Function LocalIP() As String
Dim IPList As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each IPaddress In IPList.AddressList
If (IPaddress.AddressFamily = Sockets.AddressFamily.InterNetwork) AndAlso IsPrivateIP(IPaddress.ToString()) Then
Return IPaddress.ToString
End If
Next
Return String.Empty
End Function
''' <summary>
''' Checks to see if an IP address is a local IP address.
''' </summary>
''' <param name="CheckIP">The IP address to check.</param>
''' <returns>Boolean</returns>
''' <remarks></remarks>
Private Shared Function IsPrivateIP(ByVal CheckIP As String) As Boolean
Dim Quad1, Quad2 As Integer
msg(" IS Private IP(" & CheckIP & ") ....")
Quad1 = CInt(CheckIP.Substring(0, CheckIP.IndexOf(".")))
Quad2 = CInt(CheckIP.Substring(CheckIP.IndexOf(".") + 1).Substring(0, CheckIP.IndexOf(".")))
Select Case Quad1
Case 10
msg(" TRUE - 10")
Return True
Case 172
If Quad2 >= 16 And Quad2 <= 31 Then
msg(" TRUE - 172, quad2>=16 && quad2<=31")
Return True
End If
Case 192
If Quad2 = 168 Then
msg(" TRUE - Quad2=168")
Return True
End If
End Select
msg(" Returning FALSE")
Return False
End Function
''' <summary>
''' Disposes of the UPnP class
''' </summary>
''' <param name="disposing">True or False makes no difference.</param>
''' <remarks></remarks>
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
Marshal.ReleaseComObject(staticMapping)
Marshal.ReleaseComObject(dynamicMapping)
Marshal.ReleaseComObject(upnpnat)
End Sub
''' <summary>
''' Dispose!
''' </summary>
''' <remarks></remarks>
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
''' <summary>
''' Prints out some debugging information to use.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function Print() As List(Of String)
' Return list
Dim L As New List(Of String)
' Loop through all the data after a check
If staticEnabled Then
For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping
' Add some initial data
L.Add("--------------------------------------")
'Grab the rest
L.Add(String.Format("IP: {0}", mapping.InternalClient))
L.Add(String.Format("Port: {0}", mapping.InternalPort))
L.Add(String.Format("Description: {0}", mapping.Description))
msg(" ")
msg(String.Format("IP: {0}", mapping.InternalClient))
msg(String.Format("Port: {0}", mapping.InternalPort))
msg(String.Format("Description: {0}", mapping.Description))
msg(" ")
msg(" ")
Next
End If
'Finisher
L.Add("--------------------------------------")
' Give it back
Return L
End Function
End Class
Last edited by Waxy; Jan 3rd, 2012 at 03:04 AM.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 3rd, 2012, 03:03 AM
#12
Re: VB.NET and UPnP?
Okay, try calling the Print() function to make sure that's working.
-
Jan 3rd, 2012, 03:10 AM
#13
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
PRINT Code:
================ version 1.8.0-alpha
Microsoft Windows 7 Ultimate Edition (Build 7600)
---------- version 0.9.1
>> OPEN PORT...
>> PRINT() check...
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.27
>> Port: 53814
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 63909
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.16
>> Port: 55184
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeUDP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeTCP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 61634
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.36
>> Port: 49356
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53585
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59903
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 54990
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53385
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 62077
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55945
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55705
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 65424
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 63500
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59997
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53252
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 61529
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 49508
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6783
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6784
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6785
>> Description: SplashtopStreamer
>>
>>
>> TCP...
>> mapping....
>> Checking Function Exists(port=45000, Prot=TCP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> Port not in use. Adding...
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=192.168.1.13, Port=45000, prot=TCP, desc=Dust Server)
>> Checking Function Exists(port=45000, Prot=TCP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> passed If Exists(45000, 0)
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> passed IF NOT IsPrivateIP(192.168.1.13)
>> passed 'If Not staticEnabled'
>> adding UPNP with:
>> staticMapping.Add(45000, TCP, 45000, 192.168.1.13, True,Dust Server)
>> ---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 132
>> Starting Virtual Grapics Device...
Could not load mesh, because file could not be opened: : 20kdm2.bsp
>> Loading Map...
Could not create archive for: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release/bin/defaultmedia/map-20kdm2.pk3
Could not open file of texture: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release/bin/defaultmedia/particle.bmp
>>
>> Informing Master Server/Server Browsers....
>> OK
>> MASTER SERVER says: Server Acknowledged.
>> Opening Network Port for clients...
>> Server started...
>>
>> Public Sub StartListener()
>>
>> ________________
>> CHANGING MAP TO Mayatowna1
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/Ground_ground2b.jpg
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/Ground_ground2b-bmp.jpg
Could not lock texture for making normal map.
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/floor_bluewoody1.jpg
Loaded mesh: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release\Bin\maps\Mayatowna1\Mayatowna1.obj
Needed 100ms to create OctreeTriangleSelector.(1311 nodes, 72401 polys)
>> ________________
>> MAP LOADED AND SERVER READY FOR PLAYERS!
>>
>>
>> Players/Pings:
>>
>> Players/Pings:
>>
>> Players/Pings:
>>
>> Players/Pings:
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 3rd, 2012, 03:11 AM
#14
Re: VB.NET and UPnP?
Show me all the variables you're using when adding the port mapping. I want to make sure everything is right.
-
Jan 3rd, 2012, 03:18 AM
#15
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
staticMapping.Add(45000, TCP, 45000, 192.168.1.13, True,"Dust Server")
.Add Code:
>> Port not in use. Adding...
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=192.168.1.13, Port=45000, prot=TCP, desc=Dust Server)
>> Checking Function Exists(port=45000, Prot=TCP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> passed If Exists(45000, 0)
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> passed IF NOT IsPrivateIP(192.168.1.13)
>> passed 'If Not staticEnabled'
>> adding UPNP with:
>> staticMapping.Add(45000, TCP, 45000, 192.168.1.13, True,Dust Server)
>> ---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 132
output on the fly with the lines added to the UPNP class:
msg Code:
Public Sub Add(ByVal localIP As String, ByVal Port As Integer, ByVal prot As Protocol, ByVal desc As String)
msg(" BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=" & localIP & ", Port=" & Port.ToString & ", prot=" & prot.ToString & ", desc=" & desc & ")")
' Begin utilizing
If Exists(Port, prot) Then
msg(" EXISTS = TRUE. THROWING EXCEPTION: 'This mapping already exists!', " & Port.ToString & ";" & prot.ToString)
Throw New ArgumentException("This mapping already exists!", "Port;prot")
'Remove(Port, Protocol.UDP)
Else
msg(" passed If Exists(" & Port.ToString & ", " & prot & ")")
End If
' Check
If Not IsPrivateIP(localIP) Then
msg(" IsPrivateIP(LocalIp) = False. THROWING EXCEPTION: 'This is not a local IP address!'," & localIP)
Throw New ArgumentException("This is not a local IP address!", "localIP")
Else
msg(" passed IF NOT IsPrivateIP(" & localIP & ")")
End If
' Final check!
If Not staticEnabled Then
msg(" staticEnabled=FALSE - THROWING EXCEPTION: 'UPnP is not enabled, or there was an error with UPnP Initialization.'")
Throw New ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.")
Else
msg(" passed 'If Not staticEnabled'")
End If
msg(" adding UPNP with:")
msg(" staticMapping.Add(" & Port.ToString & ", " & prot.ToString() & ", " & Port.ToString & ", " & localIP & ", True," & desc & ")")
' Okay, continue on
Try
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
staticMapping.Add(Port, prot.ToString(), Port, localIP, True, desc)
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
Catch ex As Exception
MsgBox(ex.ToString)
msg(" ---ERROR:" & ex.ToString)
End Try
End Sub
the call is:
OpenPort Code:
Function OpenPort(ByVal SubjectPort As Integer) As Boolean
Dim MyUPnPMap As New ServerUPnP
msg("OPEN PORT...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
msg(" PRINT() check...")
MyUPnPMap.Print()
Application.DoEvents()
msg(" TCP...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
msg(" mapping....")
If MyUPnPMap.Exists(SubjectPort, ServerUPnP.Protocol.TCP) Then
msg(" EXISTS=True; RETURNING FALSE!")
Return False 'already in use
Else
msg(" Port not in use. Adding...")
MyUPnPMap.Add(ServerUPnP.LocalIP, SubjectPort, ServerUPnP.Protocol.TCP, "Dust Server")
Return True 'successfully added
End If
'msg(" UDP...", System.ConsoleColor.Black, System.ConsoleColor.Cyan)
'If MyUPnPMap.Exists(SubjectPort, ServerUPnP.Protocol.UDP) Then
' msg(" EXISTS=True; RETURNING FALSE!")
' Return False 'already in use
'Else
' msg(" Port not in use. Adding...")
' MyUPnPMap.Add(ServerUPnP.LocalIP, SubjectPort, ServerUPnP.Protocol.UDP, "Dust Server")
' Return True 'successfully added
'End If
End Function
where subject port = 45000. the TCP is hardcoded (i want UDP but it's currently set to TCP due to debugging. i was checking to see if it was a protocol problem)
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 3rd, 2012, 03:24 AM
#16
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
PS:
machine i'm coding on says:
---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 132
testing machine returned the
"Not set to the instance of an object" details box that was in the image.
yes, i defined it with the DIM AS NEW keyword.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 3rd, 2012, 01:12 PM
#17
Re: VB.NET and UPnP?
I'll usually see a NullReferenceException when UPnP isn't enabled. I try and make sure everything is good before running routines, but, sometimes one slips through. I'll look into it though.
As for the COMException, I have no idea what to do about that.
-
Jan 3rd, 2012, 08:39 PM
#18
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
i know what you mean. it's a very generalized error:
"0x80040208
EVENT_E_USER_EXCEPTION
A user-supplied component or subscriber raised an exception."
http://msdn.microsoft.com/en-us/libr...rot.10%29.aspx
as you can tell from my debugging: i tried closing the port before opening it, no good.
(no error with closing, just with opening. those routines seem to work fine)
tried both tcp and udp, no good.
(both cause same error)
and different ports.
(same error)
Out of curiosity - are there any 2 UDP ports that are open by default with UPNP by windows 7?
i can always just switch ports if that's an option.
Last edited by Waxy; Jan 3rd, 2012 at 08:43 PM.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 4th, 2012, 12:14 AM
#19
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
is this any help?
NATUPNP.h
(i don't speak C)
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 4th, 2012, 06:47 AM
#20
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
also a thought:
can you pass me a simple port open/close/print() source for me to compile in vs.net 2010?
if it will compile and run on my machine then it will prove that another routine may be interfering with the upnp clas.
if it doesnt compile and run then it may prove to be a hardware problem.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 5th, 2012, 04:59 PM
#21
Re: VB.NET and UPnP?
You already have it; that DLL -is- the simple open/close/print source.
-
Jan 15th, 2012, 10:10 PM
#22
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
could it matter that, while dynamic returns true, static returns false here:
Code:
Private Sub GetStaticMappings()
Try
staticMapping = upnpnat.StaticPortMappingCollection()
Catch ex As NotImplementedException
staticEnabled = False
End Try
msg("STATIC: " & staticEnabled.ToString)
End Sub
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 16th, 2012, 01:02 AM
#23
Re: VB.NET and UPnP?
...yes that would make a big difference actually.
I need to rewrite some coding for the library to be more effective...I'll work on that.
-
Jan 16th, 2012, 04:01 PM
#24
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
Thank you formless 
and thanks for making the UPNP routines available. They are a major holdup in the project.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 16th, 2012, 08:41 PM
#25
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
full output if that helps: (includes pre- and post- PRINT routine output)
Code:
---------- version 1.8.0-alpha
Microsoft Windows 7 Ultimate Edition (Build 7600)
---------- version 0.9.1
>> Sub New() of UPNPNAT:
>> EXTERNAL IP=68.231.10.67
>> DYNAMIC:
>> True
>>
>> STATIC:
>> False
>>
>> OPEN PORT...
>> PRINT() check...
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.27
>> Port: 53814
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 63909
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.16
>> Port: 55184
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeUDP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeTCP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 61634
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.36
>> Port: 49356
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53585
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59903
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 54990
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53385
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 62077
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55945
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55705
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 65424
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 63500
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59997
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53252
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 61529
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 49508
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6783
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6784
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6785
>> Description: SplashtopStreamer
>>
>>
>> UDP...
>> mapping....
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> Port not in use. Adding...
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=192.168.1.13, Port=45000, prot=UDP, desc=Dust Server)
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> passed If Exists(45000, UDP)
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> passed IF NOT IsPrivateIP(192.168.1.13)
>> passed 'If Not staticEnabled'
>> adding UPNP with:
>> staticMapping.Add(45000, UDP, 45000, 192.168.1.13, True,Dust Server)
>> Variables Are:
>> staticEnabled As Boolean = True
>> dynamicEnabled As Boolean= False
>> ExternalIP As String =68.231.10.67
>> Port as Integer = 45000
>> prot as protocol = 1|| prot.tostring =UDP
>> LocalIp as String = 192.168.1.13
>> bEnabled as Boolean for Add function =True
>> desc Discription as String =Dust Server
>>
>> Result:
>> ---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 207
>> Sub New() of UPNPNAT:
>> EXTERNAL IP=68.231.10.67
>> DYNAMIC:
>> True
>>
>> STATIC:
>> False
>>
>> PRINT() check...
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 55474
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.27
>> Port: 53814
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.31
>> Port: 63909
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.16
>> Port: 55184
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeUDP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 25824
>> Description: LimeTCP27408B0DD8
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.15
>> Port: 61634
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.35
>> Port: 42416
>> Description: uTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.36
>> Port: 49356
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53585
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59903
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (TCP)
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 22450
>> Description: BitTorrent (UDP)
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 54990
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53385
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 62077
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55945
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 55705
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 65424
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 63500
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 59997
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 53252
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 61529
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.10
>> Port: 49508
>> Description: Teredo
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6783
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6784
>> Description: SplashtopStreamer
>>
>>
>>
>> IP: 192.168.1.13
>> Port: 6785
>> Description: SplashtopStreamer
>>
>>
>> Starting Virtual Grapics Device...
WARNING: Could not load mesh, because file could not be opened: : 20kdm2.bsp
Falling back to Echo Broadcast Server Base. No AI or Server Side collision checking.
>> Loading Map...
WARNING: Could not create archive for: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release/bin/defaultmedia/map-20kdm2.pk3
Falling back to Echo Broadcast Server Base. No AI or Server Side collision checking.
Could not open file of texture: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release/bin/defaultmedia/particle.bmp - irrelevant: virtual graphics device does not require texture.
>>
>> Informing Master Server/Server Browsers....
>> OK
>> MASTER SERVER says: Server Acknowledged.
>> Opening Network Port for clients...
>> Server started...
>>
>> Public Sub StartListener()
>>
>> ________________
>> CHANGING MAP TO Mayatowna1
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/Ground_ground2b.jpg
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/Ground_ground2b-bmp.jpg
Could not lock texture for making normal map. - irrelevant, virtual graphics device.
Loaded texture: E:/Program Files/Microsoft Visual Studio 10.0/My Documents/Projects/DUST/DustClient/Bin/Release/Bin/maps/Mayatowna1/floor_bluewoody1.jpg
Loaded mesh: E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustClient\Bin\Release\Bin\maps\Mayatowna1\Mayatowna1.obj
Needed 93ms to create OctreeTriangleSelector.(1311 nodes, 72401 polys)
>> ________________
>> MAP LOADED AND SERVER READY FOR PLAYERS!
>>
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 16th, 2012, 09:03 PM
#26
Re: VB.NET and UPnP?
The issue is that I'm adding to the StaticMapping, regardless of if it's available or not. I need to fix the code to add to either both or just one if the other isn't available.
I'll fix it in the future when I have some more time.
-
Jan 17th, 2012, 01:08 AM
#27
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
this is odd...
i just noticed: when doing New()
Code:
>> Sub New() of UPNPNAT:
>> EXTERNAL IP=68.231.10.67
>> DYNAMIC:
>> True
>>
>> STATIC:
>> False
but when doing .add():
Code:
Variables Are:
>> staticEnabled As Boolean = True
>> dynamicEnabled As Boolean= False
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 17th, 2012, 01:09 AM
#28
Re: VB.NET and UPnP?
I'll have to look into it; I'm not sure.
-
Jan 17th, 2012, 01:22 AM
#29
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
it was an error on my part. correct output:
Code:
>> Sub New() of UPNPNAT:
>> EXTERNAL IP=68.231.10.67
>> STATIC:
>> True
>>
>> DYNAMIC:
>> False
Code:
>> UDP...
>> mapping....
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> Port not in use. Adding...
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> BEGINNING UPNP ADD IN CLASS: Sub Add(LocalIP=192.168.1.13, Port=45000, prot=UDP, desc=Dust Server)
>> Checking Function Exists(port=45000, Prot=UDP) ....
>> Mapping For-Each check passed.
>> Returning FALSE
>>
>> passed If Exists(45000, UDP)
>> IS Private IP(192.168.1.13) ....
>> TRUE - Quad2=168
>> passed IF NOT IsPrivateIP(192.168.1.13)
>> passed 'If Not staticEnabled'
>> adding UPNP with:
>> staticMapping.Add(45000, UDP, 45000, 192.168.1.13, True,Dust Server)
>> Variables Are:
>> staticEnabled As Boolean = True
>> dynamicEnabled As Boolean= False
>> ExternalIP As String =68.231.10.67
>> Port as Integer = 45000
>> prot as protocol = 1|| prot.tostring =UDP
>> LocalIp as String = 192.168.1.13
>> bEnabled as Boolean for Add function =True
>> desc Discription as String =Dust Server
>>
>> Result:
>> EXTERNAL IP=68.231.10.67
>> ---ERROR:System.Runtime.InteropServices.COMException (0x80040208): A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208)
at NATUPNPLib.IStaticPortMappingCollection.Add(Int32 lExternalPort, String bstrProtocol, Int32 lInternalPort, String bstrInternalClient, Boolean bEnabled, String bstrDescription)
at DustServer.ServerUPnP.Add(String localIP, Int32 Port, Protocol prot, String desc) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\ServerUPnP.vb:line 208
>> Sub New() of UPNPNAT:
>> EXTERNAL IP=68.231.10.67
>> STATIC:
>> True
>>
>> DYNAMIC:
>> False
>>
>> PRINT() check...

Cisco Linksys E3000
Last edited by Waxy; Jan 17th, 2012 at 01:59 AM.
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Jan 18th, 2012, 09:31 AM
#30
Thread Starter
Hyperactive Member
Re: VB.NET and UPnP?
think i found the incompatibility with your routines.
i resorted to a different Library than UPnPNAT.
here's the link to the service difference if you choose to update it:
http://managedupnp.codeplex.com/discussions/286523
i'll code it and test it tonite if i have time, but it should be the solution i need.
(sent from my ipad)
----------------------------------------------------
Missing the days of GWBasic 1.1
WaxyStudios.com
-
Feb 6th, 2013, 02:02 PM
#31
New Member
Re: VB.NET and UPnP?
Hey, Waxy. Did you succeed to compete this task? I'm having the same problem. What about managed upnp? Was it any help?
-
Feb 28th, 2013, 09:44 PM
#32
Lively Member
Re: VB.NET and UPnP?
For the life of me I cannot get this to work. I'm always receiving Object reference not set to an instance of an object.
at this line:
Code:
For Each mapping As NATUPNPLib.IStaticPortMapping In staticMapping
under this: Public Function Exists(ByVal Port As Integer, ByVal Prot As Protocol) As Boolean
here's my code:
Dim portforward As New UPNP
If portforward.Exists(6550, UPNP.Protocol.UDP) Then
Debugger.Break()
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|