I'm trying to set up a basic network connection using the droid emulators with eclipse but I'm having problems. The server reaches the line "Socket s = ss.accept();" and waits for the client to connect, but the client can't seem to connect.
Now I've been able to have my client connect to a python server that I created and does the same thing as the server I made for the droid. I've allowed the Internet Uses on both client and server in the AndroidManifest so I'm at a lose as to why this server isn't working on my droid emulator.
Sever:
ServerSocket ss = new ServerSocket(8888);
while(!end){
Socket s = ss.accept();
Log.v("Server","Connection found");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter output = new PrintWriter(s.getOutputStream(),true);
String st = input.readLine();
Client:
Socket s = new Socket(MYIPADDR,8888);
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
Any help would be greatly appreciated.
Just adding to Luka's answer since you're probably going to run into future issues:
If you're using sockets, you may want to use a library to help with all the maintenance that's really required for a stable connection.
A good library to use for handling the connection would be: https://github.com/koush/android-websockets
It'll keep the connection alive and is fairly simple to change around to fit your sending needs. The only thing it's missing is a callback feature to deal with incoming data, but that would be way easier to implement than entirely setting up something from scratch to deal with the whole connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With