Send text from android to pc via wifi connection

I am new to Android programming and stackoverflow. I want to create an application that sends some information (like text) to a computer on the same network (Wi-fi) and reads to a PC using a Java application. Any ideas how to get started? Sorry for my bad english

+2
java android
source share
2 answers

You must use the wifi manager in client and server programs and install wifi directly between PC and Android.

For permissions use this:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> 

The server uses:

 ServerSocket serverSocket = new ServerSocket(9000); Socket socket = serverSocket.accept(); 

And in the 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\n"; outputStream.write(txt.getBytes()); //in client String message = inputStream.readLine(); socket.close(); 

The server sends the text, and the client checks the input stream for "\ n".

+3
source share

As user5001333 said, you should create a server-client template using sockets, for example.

In Android, you cannot perform network operations in the main thread, so you need to create a background thread (for example, asynctask) that establishes a connection between you (the client) and the PC (server).

0
source share

All Articles