Well, i have a task to write Tcp Client for Andoid on java. Before, i have only work with C++ & Qt, it was easy =)
Now i tried to find out the best way to solve this task.
I want to devide Client on two thread.
The first one will be waiting and handling requests from server, on the second i will have GUI or ill can sending some requests to server (not matter).
Client will be connecting to the server and waiting for the some updating. On the server we have DB which can be edited by client. We must notify about changes on server definite group of users and they can do smth after.
Do you think is ok to devide it, or there are more good way? And how it can be implemented more clear.
ps guys, i have a some practice with Tcp-Ip, i dont needed on basic tutorials in this area! And i’m ok with Java. I need help just with architecture for building Client. Please, my question is strongly definite.
pps really sorry if it was hard to understand 😉
First your question : is it ok to divide your client into two threads ?
Well it depends on the kind of application you are running. If your client is interacting with the server along well defined client-server cases, it could be enough to use a same thread to send a message to the server and then block while waiting for the answer.
However, this makes your program fairly not flexible, and if the server or the connection do not behave as they should, you will get a freeze of your ui at least.
So it is IMHO rather necessary to use several threads for such communication handling. One thread will handle the receiving of messages and its processing, while the ui thread will call message sending.
Here is a simple implementation which you can adapt to your case easily :