Reputation: 13051
i need to do the same of this:
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class ClientSocketExample {
public static void main(String[] args) {
try {
//
// Create a connection to the server socket on the server application
//
InetAddress host = InetAddress.getLocalHost();
Socket socket = new Socket(host.getHostName(), 7777);
//
// Send a message to the client application
//
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject("Hello There...");
//
// Read and display the response message sent by server application
//
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
String message = (String) ois.readObject();
System.out.println("Message: " + message);
ois.close();
oos.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
but in objective-c, i see that there are many classes that uses socket, but i don't know how to use it in an iphone project, can someone help me? thanks!!!
Upvotes: 0
Views: 1554
Reputation: 5977
you may upload it Asynchronously, record it completely ,then fully upload it after
or just NSStream or pure TCP Socket as in unix and i use cocoaAsyncSocket
- (void)initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 80, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
}
Upvotes: 1