Java 如何在objective-c中实现客户端套接字
我也需要这样做:Java 如何在objective-c中实现客户端套接字,java,iphone,objective-c,sockets,Java,Iphone,Objective C,Sockets,我也需要这样做: 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 clas
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();
}
}
}
但在objective-c中,我看到有许多类使用socket,但我不知道如何在iphone项目中使用它,有人能帮我吗?谢谢 您可以异步上传,完整记录,然后在 或者像在unix和我使用的那样使用TCP套接字
请参阅此链接:您只能将ObjectInput/OutputStream用于另一个Java程序。我建议您使用XML、JSon或其他文本协议等可移植格式。
- (void)initNetworkCommunication {
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 80, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
}