I bought a gps, I tested this with sms message and with its own software to retrieve the lat / long and it works fine , see the screenshot :
Now I'm sure that the communication with gprs->internet
works so I want to create my own software who can do a lot of other functionality that does not exist with the software manufacturer..
In my first reflection, I tried to listen the NMEA messages with socket tcp/ip (java) on the port 7070 , here is my source code:
import java.io.*;
import java.net.*;
public class Serveur {
static final int port = 7070;
public static void main(String[] args) throws Exception {
ServerSocket s = new ServerSocket(port);
System.out.println("waiting for connexion from GPS 7070");
Socket socClient = s.accept();
System.out.println("Connexion GPS ok");
BufferedReader in = new BufferedReader(
new InputStreamReader(socClient.getInputStream())
);
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(socClient.getOutputStream())),
true);
String str = in.readLine();
System.out.println("the GPS message is : " + str);
in.close();
out.close();
socClient.close();
}
}
I tried to send a message through a java client on the local network, and it works..
But the problem that I do not understand is : when I receive a message from the GPS, i get this error :
waiting for connexion from GPS 7070
Connexion GPS ok
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at serveur.Serveur.main(Serveur.java:27)
at serveur.Serveur.main(Serveur.java:27)
the error comes from the line String str = in.readLine();
if its software was able to intercept the message NMEA why not my application ??
UPDATE:
I sniffed the network ,here is the result :
[the protocol used by my GPS][4]
the first packet received from the GPS (the hidden ip adress is my fixed public address
):
the first response from the software(1/2) (its an empty message):
from the software(2/2):
from the GPS:
from the soft:
from the GPS(1/2)(its an empty message):
and finally the long/lat/speed... from the GPS(2/2):
as I have already written, there are empty messages sent by the GPS...So here is all details.
@Peter Lawrey:I tried to read the message byte by byte but I got an error from netbeans,,,can you give me a piece of code? thanks Hope this help me.