I am developing a fleet application where I need to track my vehicle movement and store that into a MySQL db. Am using GT 06 GPS with a sim card.
I created a Java file for checking that GPS is sending the data or not. My program is connected with the GPS but the data I am receiving is not clear. How can U parse the data or is the data I am receiving is wrong?
Below is the program I am using:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class BackupServerListener {
public static void main(String[] args) {
new ServerListener().startServer();
}
public void startServer() {
final ExecutorService clientProcessingPool = Executors.newFixedThreadPool(03);
Runnable serverTask = new Runnable() {
@SuppressWarnings("resource")
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(9876);
System.out.println("Waiting for clients to connect...");
while (true) {
Socket clientSocket = serverSocket.accept();
clientProcessingPool.submit(new ClientTask(clientSocket));
}
} catch (IOException e) {
System.err.println("Unable to process client request");
e.printStackTrace();
}
}
};
Thread serverThread = new Thread(serverTask);
serverThread.start();
}
private class ClientTask implements Runnable {
private final Socket clientSocket;
private ClientTask(Socket clientSocket) {
this.clientSocket = clientSocket;
}
public void run() {
System.out.println("Got a client !");
while (true) {
try {
BufferedReader reader = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
String clientData = "";
clientData = reader.readLine();
String hex_value = asciiToHex(clientData);
System.out.println("clientdata::::"+hex_value);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private String asciiToHex(String clientData) {
char[] chars = clientData.toCharArray();
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++)
{
hex.append(Integer.toHexString((int)chars[i]));
}
return hex.toString();
}
}
}