Subject: problem with socket connection
Posted By: sowmya1 Post Date: 1/21/2006 11:11:19 PM
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,180.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,180.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,180.000,101102,,*1C
$GPGSA,A,1,,,,,,,,,,,,,,,,*32

if you can figure out the problem, please let me know

Reply By: ciderpunx Reply Date: 1/23/2006 12:36:43 PM
Just a guess but try import java.net.*; as well as importing java.net.socket - it looks like it's having problems converting localhost into an IP (it's a while since I did any java socket stuff).

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com

Go to topic 39073

Return to index page 387
Return to index page 386
Return to index page 385
Return to index page 384
Return to index page 383
Return to index page 382
Return to index page 381
Return to index page 380
Return to index page 379
Return to index page 378