I just learned Android and Java programming (very noob inside), and I would like to ask some questions regarding android programming and Socket Server.
I got an assignment to create a simple chess application (excluding the AI), the position of pawn will be retrieved from TCP socket in :
Server : xinuc.org
Port : 7387
I was told to use Socket Persistent because Server will update pawn's position in every second, the pawns position will be sent in this format
[Pawn's Code] [Horizontal Position] [Vertical Position] [space],
Pawn's Code :
K: White King
Q: White Queen
B: White Bishop
N: White Knight
R: White Rook
k: Black King
q: Black Queen
b: Black Bishop
n: Black Knight
r: Black Rook
For example : Ka1 Qg3 Be6 and so on.
Then my application have to adjust the retrieved position and move the pawns accordingly.
I've read some tutorial about Android Socket Programming, and still kinda confuse though, I used AsyncTask instead of Thread because I read that AsyncTask will be a better option in this case.
And after read and learn a bit about it, here is how I retrieve data with Socket (in doInBackground):
try {
clientSocket = new Socket(SERVERADD, SERVERPORT);
InputStreamReader inputStream = new InputStreamReader(clientSocket.getInputStream());
BufferedReader reader = new BufferedReader(inputStream);
String latestPosition = reader.readLine();
storedPosition=latestPosition;
} catch (UnknownHostException e) {
Log.d("Error Unknown Host", String.valueOf(e));
} catch (IOException e) {
Log.d("Error IOException", String.valueOf(e));
}
I don't think the code I put above to retrieve data from Socket is the best practice, CMIIW.
So that is the (quite long and boring) background to support my question below, I have two main questions here :
I am a little bit clueless about what I am doing here, will the code I provided above able to read the data from Client?
And after I retrieve the data, I should move the pawn's position accordingly. And I still have no single clue about how it should be done (About how I create the board, and move the pawns position). Can you tell me in a more understandable way how it should be done?
I've Read these : Android Chess Game Example Android Source Code - Chess,
But I think they are too complicated for me,
Thank you in Advance