You should use wi-fi manager in client and server programs and set wifi direct between PC and Android.
For the permissions use this:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
In server use :
ServerSocket serverSocket = new ServerSocket(9000);
Socket socket = serverSocket.accept();
And in client :
socket = new Socket()
socket.connect("192.168.49.(Server Device wi-fi IP(zero to 255))" , 9000);
Then use these methods in both programs for send-receive data
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
BufferedReader inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//in server
String txt = "Hello from Server to Client
";
outputStream.write(txt.getBytes());
//in client
String message = inputStream.readLine();
socket.close();
Server sends the text and client checks the input stream for a '
' in it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…