problem with socket connection
i have my gps reciver connected to the usb port - i have a daemon gpsd running which makes data available on tcp port 2947 for querying. when i do telnet, it gives proper data.
but when i open a socket connection using java, it does not print anything as output. actually telnet asks for an escape charatcer so i am sending "r" initially to the server but still the program does not print anything as output.
here is my java code -
import java.io.*;
import java.net.Socket;
public class test2
{
public static void main(String[] args)
{
try
{
Socket s = new Socket("localhost",2947);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
s.getOutputStream())),true);
out.println("r");
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line;
while(true)
{
line = in.readLine();
System.out.println(line);
}
}
catch (Exception e)
{
}
}
}
or sometimes it even shows error as
Exception in thread "main" java.net.SocketException: Invalid argument or cannot assign requested address
at java.net.PlainSocketImpl.socketConnect(Native Method)
and this is the output which i get on telnet -
ot@localhost ~]# telnet localhost 2947
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
r
GPSD,R=1
$GPRMC,000212,V,18000.0000,N,00000.0000,W,0.0000,1 80.000,101102,,*1A
$GPGSA,A,1,,,,,,,,,,,,,,,,*32
$PGRME,400.00,0.00,0.00*7B
$GPRMC,000213,V,18000.0000,N,00000.0000,W,0.0000,1 80.000,101102,,*1B
$GPGSA,A,1,,,,,,,,,,,,,,,,*32
$PGRME,400.00,0.00,0.00*7B
$GPRMC,000214,V,18000.0000,N,00000.0000,W,0.0000,1 80.000,101102,,*1C
$GPGSA,A,1,,,,,,,,,,,,,,,,*32
if you can figure out the problem, please let me know
|