Search the Community
Showing results for tags 'Socket Programming'.
-
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
- 1 reply
-
- Socket Programming
- Tracking Device
-
(and 1 more)
Tagged with: