Hi,

I have an issue here I am trying to solve. I am attempting to write a client and library for an api. The api has some parameters passed to it via php GET variables. So my library uses a socket to get the page, for example I have a method in the library for getting profile info, which gets the data from http://wherever.com/api.php?key=xxx&...nfo&userid=xxx.

My current method is to open a URLConnector to that location and retrieve the data. The problem is that this is a blocking socket so my program becomes unresponsive until the data is all returned.

What I would like instead to do is have the method getProfileInfo take in a user id and a callback function, so I could do getUserInfo(1234,userInfoArrived); and have the userInfoArrived (which takes a string parameter) called once all the data is read. Then in my library I can run the socket in a new thread.

I'm having trouble passing a function as a parameter though. I searched online and found something about using delegates but I didn't understand anything they were talking about. If that's the way to go, can someone give me an example of how I would do such a thing?

Alternatively, can you suggest a better way to have non-blocking sockets? In the future I plan to drop the URLConnector and do all the http work myself with an ordinary socket, as I want to include a further api that uses tokens passed as header parameters.