0

i've written a short TCP-Server and TCP-Client in Java. Everthing worked fine while running the TCP-communication. Today I tried to implement my Server in an android-app and got problems with the serversocket.accept-method. Everytime the line with the method call serversocket.accept() is executed the systems breaks down.

Do I've to use threads to solve the problem. Or is there any other solution for this Problem?

1
  • 1
    Always put sockets in thread as they will block the UI thread when it is reading. Commented Sep 21, 2011 at 10:05

1 Answer 1

1

The system doesn't "breaks". When you launch the "accept()" method, the program waits for an incoming connection. So if it's the activity thread that start this method, it freezes until it has an incoming connection. But if an activity doesn't respond for over 5 second, the program is broken.

Try using a Thread, it's not hard really...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.