Reputation: 1309
i'm currently attempting to connect emulator(client) and phone(server) through TCP/IP socket connection. But somehow it never works, but it works fine if i try to connect emulator (as client / server) with internal java program (as client / server), also socket connection works fine from phone to applications that's not on emulator. I thought it has something to do with port forwarding so I've tried:
sourced from How can I forward my localhost IP-Address to an Android Emulator
telnet localhost 5554
redir add tcp:1337:12345
But when i test my client side with port number 1337 and server side 12345, it still doesn't work, server code doesn't .accept() client's request.
Following is my client(emulator) and server(phone) code for accepting and setting up io streams
client:
SERVER_IP is the local ip address
connection = new Socket(SERVER_IP, PORT);
private void setUpStreams() throws IOException {
output = new ObjectOutputStream(connection.getOutputStream());
output.flush();
input = new ObjectInputStream(connection.getInputStream());
}
Server:
That's for accepting user private void acceptingUser() {
try {
ss = new ServerSocket(PORT, 10);
connection = ss.accept();
connected = true;
osm.updateInChatStatus(1);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("serv", "Wasn't able to connect with any clients!: " + e);
}
}
and setting up stream is pretty much similar to the client's one. Thanks in advance for ur advices and solutions.
Upvotes: 3
Views: 2388
Reputation: 5297
To access network connection, you need to set the permission in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bosch.adx.esidroid">
<uses-permission android:name="android.permission.INTERNET" />
<application
--
Upvotes: 0