0
我需要做同樣的這個:如何實現Objective-C中的客戶端的Socket
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,我看到有使用插座很多類,但我不知道如何在iPhone項目中使用它,有人可以幫助我嗎?謝謝!!!
參考以下鏈接上傳:HTTP:/ /stackoverflow.com/questions/6240696/creating-a-socket-client-in-objective-c-mac-osx – Hector
您只能在另一個Java程序中使用ObjectInput/OutputStream。我建議你使用可移植的格式,如XML,JSon或其他文本協議。 –