Jump to content

Socket Programming issue for GPS Tracking Devices


Recommended Posts

Dear Friends,

 

Me and my colleagues are trying to make an application for routing purposes. This application has to be in a mutual transaction with a GPS tracking device obviously. Here come the issues we encounter

 

1. We are getting the login data but after that we need to send response to device with a format that device can verify server and then send actual GPS data to server.

2. We are not able to send login data to that device so that's why device not send us GPS data.

3. Login Data we are getting is like :- 2323101501f357367031649441529625060.

4. We are not getting further process what to do to get Device GPS data to our server.

 

We have asked for the GPS device support, no useful information but offering their own portal.

 

and here is the code developed for this transaction :

package com.trackit;

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 ServerListener {

    public static void main(String[] args) {
        new ServerListener().startServer();
    }

    public void startServer() {
        final ExecutorService clientProcessingPool = Executors.newFixedThreadPool(03);

        Runnable serverTask = new Runnable() {
            @SuppressWarnings("resource")
			@Override
            public void run() {
                try {
                    ServerSocket serverSocket = new ServerSocket(5094);
                    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;
        }

        @Override
        public void run() {
            System.out.println("Got a client !");
            try {
                BufferedReader reader = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
                String clientData = "";
                
                clientData = reader.readLine();
                
                String hex_value = asciiToHex(clientData);
                
                System.out.println("Hex Value :-"+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();
		}
	 }

}

Any kind of tips and help is appreciated.

Kindly Regards

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.

Disable-Adblock.png

 

If you enjoy our contents, support us by Disable ads Blocker or add GIS-area to your ads blocker whitelist