Im trying to wrap a socket class and need to get the local port, if any, and
local address. when I accept a new connection, I create a new socket, and a
new instance of my clsSocket and call the sub New(byval newsocket as
Socket). Here's what this looks like:
Public Sub New(ByVal newSocket As Socket)
If newSocket.AddressFamily = AddressFamily.InterNetwork And _
newSocket.SocketType = SocketType.Stream And _
newSocket.ProtocolType = ProtocolType.Tcp Then
If newSocket.Connected Then
myRemoteAddress = CType(newSocket.RemoteEndPoint,
IPEndPoint).Address
myRemotePort = CType(newSocket.RemoteEndPoint, IPEndPoint).Port
Try
mylocalAddress = CType(newSocket.LocalEndPoint,
IPEndPoint).Address
mylocalPort = CType(newSocket.LocalEndPoint, IPEndPoint).Port
Catch e As SocketException
Catch e As Exception
End Try
soc = newSocket
m_currentState = state.connected
beginReceive()
End If
End If
End Sub
when I include the code in the try catch block the it doesnt return anything
and errors with "Object reference not set(null)". Im not sure what Im doing
wrong here. I need to get the localport the new connections is going to
continue on. suggestions?
mhm