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
