Server Socket In Java (android)
Hello all I am writing server socket inside my Android app. It should allow only one client. Interesting thing is that I want my server to send messages(strings) to client while th
Solution 1:
- You probably want to use a BlockingQueue.
This is the typical way to implement a producer-comsumer pattern: the producer will put()
a string in the queue, the server/consumer will take()
a string from the queue. If the queue is empty the server will block and wait, optionally with a timeout.
You probably don't need to bound the queue, so you could instantiate a LinkedBlockingQueue with its empty constructor.
All implementations of BlockingQueue
are thread-safe, so you don't need additional synchronisation for their basic operations.
Post a Comment for "Server Socket In Java (android)"