I have read this Bluetooth Chat post, and this Transfer file post.And I have two real android devices ,not AVDs, my intent is to set IP address and port in one device which acts as a Client while the other acts as a Server.
They are using WIFI,and I have connected both of them to PC respectively.Get into adb shell ,and ping each other.It works. I have written client code like this:
Socket socket = new Socket("192.168.1.142",8888);
InputStream in = socket.getInputStream();
byte[] buffer = new byte[in.available()];
Toast.makeText(this, String.valueOf(in.available()), Toast.LENGTH_LONG).show();
in.read(buffer);
String msg = new String(buffer);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
and the Server:
ServerSocket server = new ServerSocket(8888);
while(true) {
Socket client = server.accept();
OutputStream out = client.getOutputStream();
String msg = "Hello Android!";
out.write(msg.getBytes());
client.close();
}
I have add this
<uses-permission android:name="android.permission.INTERNET" />
to manifest.
But no response. I have two questions:
1.Why there is no response in my client?
2.How to handle with sqlite3 database ,there must be something different with ordinary text files,but what is the difference?
Any suggestions will be very appreciated.
It would be unwise to transfer a sqlite3 .db between devices that may be differing make/model/manufacturer/etc. Rather, you should dump the schema and content of database to csv or sql and transfer that. You may want to compress the file too before transfer.
As for networking with Android. If you're using an AVD (emulator) then you're going to find it impossible or near impossible. Your proxy also plays a role in networking so you need to be warey of what it allows, how it's currently configured, and how it behaves (bugs, quirks, features). You should use a tool such as wireshark to inspect network comms and make sure that your App is even sending something out before worrying whether that something gets recieved.