I'd say stick with the obvious, but please back up a bit to where it's not obvious to a newbie. ar is System.Net.Sockets.OverlappedAsyncResult ar.AsyncState is null
how do I get a socket/state and pass it? Public Sub New(ByVal client As TcpClient) Me.client = client Me.client.GetStream.BeginRead(readBuffer, 0, READ_BUFFER_SIZE, AddressOf StreamReceiver, Nothing) End Sub Private client As TcpClient Private readBuffer(READ_BUFFER_SIZE) As Byte Private strName As String Private Sub StreamReceiver(ByVal ar As IAsyncResult) 'get the clients ip address Dim ClientSocket As Socket = CType(ar.AsyncState, Socket) Dim ClientSocket As Socket = client.??? Dim ClientIPAddress as string =ClientSocket .RemoteEndPoint.ToString()) ----- Original Message ----- From: "Ian Griffiths" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 20, 2004 9:49 AM Subject: Re: [ADVANCED-DOTNET] Client IP Address At the risk of going for the obvious question, are you actually passing in the socket as the 'state' parameter when you call BeginConnect? If 'client' is null in this situation, that implies that ar.AsyncState was also null, which implies that you passed in null as the 'state' parameter when you called BeginConnect. -- Ian Griffiths - DevelopMentor http://www.interact-sw.co.uk/iangblog/ > -----Original Message----- > From: Peter Suter > > After "Dim client As Socket = CType(ar.AsyncState, Socket)", > client = nothing, and any attempt to use client throws > > "An unhandled exception of type System.NullReferenceException occurred in > ... > Object reference not set to an instance of an object' > > So, my issue seems to be not that I get an exception, but that > client=Nothing in the first place. > > Thanks for any suggestions > > ----- Original Message ----- > From: "Ian Griffiths" <[EMAIL PROTECTED]> > > What is the exception that you're getting? > > > -----Original Message----- > > From: Peter Suter > > > > Hi All, > > In a sub much like this one, from "Using an Asynchronous Client Socket > > [Visual Basic]", I keep getting an exception rather than a socket. > > Is there a problem getting the socket using this technique? > > (I'm trying to get the Client IP Address) > > > > Private Shared Sub ConnectCallback(ar As IAsyncResult) > > Try > > ' Retrieve the socket from the state object. > > Dim client As Socket = CType(ar.AsyncState, Socket) > > > > ' Complete the connection. > > client.EndConnect(ar) > > > > Console.WriteLine("Socket connected to {0}", _ > > client.RemoteEndPoint.ToString()) > > > > ' Signal that the connection has been made. > > connectDone.Set() > > Catch e As Exception > > Console.WriteLine(e.ToString()) > > End Try > > End Sub 'ConnectCallback =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor� http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com
