+1  A: 

First question:

You are already initializing it with a socket. NSStream's getStreamsToHost message already gives you a socket to talk to specified host, post. Whenever you want to write to the socket, just use oStream.

Second question:

Kind of answered in the first question. Keep in mind that you are opening a socket to port 80. So, probably you are running a WebServer on the remote host. And to be able to send an image to the remote server, you would need to implement HTTP protocol. Check my suggestion below. I think it will make your life easier.


A little suggestion:

I know you didn't ask this, but let me give you a suggestion. You are trying to send an image through a socket. I would use a higher level protocol such as HTTP or FTP to do that. Using a plain socket will force you to implement a new protocol yourself, not to mention the server side code to process incoming images.

So, if you use HTTP, just write a little server side script in your favorite WEB developing platform (.NET, PHP, Java, Python, RoR, CGI, whatever) and just use guidelines on this WebPage to submit the image on iPhone. It's way easier.

Pablo Santa Cruz
When can I add UIImage data to the oStream? After [oStream open] or before 'getStreamToHost'?
iPhoney
It's to be after. But remember, if you are sending it to the 80 port, you are probably sending it to a Web Server. So you will have to implement HTTP protocol yourself. Please read carefully my answer. You'll be able to transmit your image if you follow my suggestions.
Pablo Santa Cruz
For my own app, port 1100 is used. And it shares the same server with a window mobile app. So I won't be allowed to change the protocol. Thanks for your answer and suggestion anyway.
iPhoney
If you are using port 1100 for your application, you should change this part of your code to reflect it: [NSStream getStreamsToHost:host port:80 inputStream:nil outputStream:
Pablo Santa Cruz