Hi all,
I'm having some issues with sending data from an Android client to a
desktop server over TCP via wifi. The emulator works fine, but on the
actual phone, the connection cannot be established. A "socket not
connected" exception was thrown.
I have attached my code below.
Any help, please? Many thanks!
// CODE inside an Activity
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.send:
sendMessage();
return true;
/// ...other items
}
}
private void sendMessage() {
String serverAddr = "18.xxx.xx.xxx";
Socket socket = null;
try {
socket = new Socket(serverAddr, 4444); //
EXCEPTION HAPPENS HERE
} catch (Exception e) {
//show exception on screen
}
String message = "some message";
try {
PrintWriter out = new
PrintWriter(socket.getOutputStream(), true);
out.println(message);
} catch (Exception e) {
//show exception on screen
} finally {
socket.close();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en