Google'da arama yaptım. Çok denedim. Android 2.2 ve sdk 8'de Android'de bir Listede SSID'yi nasıl kullanabilirim? SSID kullanarak Program aracılığıyla özel wifi özellikli cihaz özelliklerini almalısınız. Bu yardımla, verileri Android'de iki Wifi özellikli cihaz arasında aktarmalı. Bu plzde bana yardım eden var mı? İki Android aygıtı arasında anlamlı bir şekilde veri göndermek için bir TCP bağlantısı kullanmanız gerekir.İki Wifi Aygıtı arasındaki veri aktarımı
6
A
cevap
17
Bunu yapmak için, ip adresi ve diğer cihazın dinlediği bağlantı noktasına ihtiyacınız vardır.
Örnekler here'dan alınmıştır. Sunucu soketine bağlanan bir soket gerek istemci tarafında için
try {
Boolean end = false;
ServerSocket ss = new ServerSocket(12345);
while(!end){
//Server is waiting for client here, if needed
Socket s = ss.accept();
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter output = new PrintWriter(s.getOutputStream(),true); //Autoflush
String st = input.readLine();
Log.d("Tcp Example", "From client: "+st);
output.println("Good bye and thanks for all the fish :)");
s.close();
if (STOPPING conditions){ end = true; }
}
ss.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
: sunucu tarafı (dinleme tarafı) için
bir sunucu soketi gerekir. Uzaktan Android cihazlar ip adresi ya da hostname ile "localhost" yerine edin: kodu içintry {
Socket s = new Socket("localhost",12345);
//outgoing stream redirect to socket
OutputStream out = s.getOutputStream();
PrintWriter output = new PrintWriter(out);
output.println("Hello Android!");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
//read line(s)
String st = input.readLine();
//. . .
//Close connection
s.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
2
For data Transfer between 2 devices over the wifi can be done by using "TCP" protocol. Connection between Client and Server requires 3 things
1) Using NSD Manager, Client device should get server/host IP Address.
2) Send data to server using Socket.
3) Client should send its IP Address to server/host for bi-directional communication.
google geliştiricileri bu link
For faster transmission of data over wifi can be done by using "WifiDirect"
which is a "p2p" connection. so that this will transfer the data from
one to other device without an Intermediate(Socket). For Example catch
bu bağlantıya bakın doğrulaması ise wifip2p ve P2P Connection with Wi-Fi
Bir örnek yakala Github WifiDirectFileTransfer