The socket code you have here is basically an Image reader which is also supported by the Philips HTTP Library. Do you have that library and have you tried using it?
Is the code above in a button or in a page script? It makes a difference due to the variable scoping of 'socket'.
Have you attempted any of the examples from the Dev Guide thus far and did you encounter any specific errors?