2

I have developed an android app, which works well in android 2.3 but not in android 4.2.

The app creates a socket connection and sends data to the server. The problem is with socket connection. Please help me.

The code for socket connection is:

Socket socket = new Socket();
int timeout=30000;
socket.connect(sockaddr, timeout);
//sockaddr is user defined.
//sockaddr address has server ip address and port
AJPerez
  • 3,435
  • 10
  • 61
  • 91
Arun
  • 72
  • 2
  • 8
  • Please post exception stacktrace. If I had to guess, I'd say there's NetworkOnMainThreadException. – laalto Mar 07 '14 at 10:23
  • is this your problem http://stackoverflow.com/questions/22247231/no-authentication-challenge-found – Ranjit Mar 07 '14 at 10:26

2 Answers2

1

since Android Version 3.0 (API 11) it is not allowed to make network activity on the main thread of your app.

Here a Link to the Exception that (i think) is thrown by your app (look at your logcat for more information). NetworkOnMainThreadException

Try to do all your network activities with an AsyncTask.

I hope this will help you. =)

ColdFaith
  • 401
  • 4
  • 13
0

You need to perform Socket connection asynchronously, as from Android 3.0 onwards, this isn't allowed on Main thread.

pratiti-systematix
  • 792
  • 11
  • 28