473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problems with sockets and LocalEndPoint

mhm
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
Nov 21 '05 #1
0 869

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
1
by: jm | last post by:
Easy probably, please read on. I know some of you have commented already about some of my socket question. I appreciate that. I have a Form1: static void Main() { Application.Run(new...
3
by: Andrew Ducker | last post by:
I have the following code, which throws an error of "An invalid argument was supplied" when I run it. Can anyone tell me the stupid mistake I'm obviously making? Socket listener = new...
0
by: Gregory Hassett | last post by:
I am writing a loop which will listen on a given port for incoming UDP packets. If the UDP sender (client), terminates abnormally, then my call to socket.BeginReceiveFrom throws a SocketException....
1
by: Bob | last post by:
I am trying to reuse a socket address but I am having problems. What I am doing is creating a socket, connecting, then getting the LocalEnd point. I then Disconnect and try to connect again using...
0
by: ZR | last post by:
I am writing two applications which needs to (among other things) communicate through network, so one of them is a client and the other one is a server. I have used asynchronous socket examples...
8
by: Mike Owen | last post by:
Hi, I am using the following code to send email on a Windows 2003 Web Server: Imports System.Net.Mail ........ Dim msgmail As New MailMessage msgmail.To.Add(New...
0
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call BeginReceiveFrom). I am trying to read data...
0
by: nsutanto | last post by:
Hello, I have 2 instances of server. Both instances create UDP socket listening for incoming messages. It seems that only 1 instace of my server can listen to the messages, the other seems to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.