i want to write an App for Android and a java-program for pc(in my case: windows 8.1) which should communicate with each other using Sockets. My PC would be the server and the phone the client.
My Server code so far:
import java.net.ServerSocket;
import java.net.Socket;
public class TestServer {
public static void main(String[] Args) {
Socket socket = null;
ServerSocket server = null;
try {
server = new ServerSocket(4736);
socket = server.accept();
System.out.println("Connected");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// TODO
try
{
socket.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
In my android app i now want to create an instance of Socket. What do i have to put in the arguments of the Socket-Constructor? What permissions do i need?
PS:I know that i have to do it in an extra thread.
您需要INTERNET许可,并提供ip和port作为套接字的参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.