Thanks for your reply.
I uninstalled the gpsd (3.9) from my computer, which were installed by the sudo apt-get install commands.
address@hidden:~$ gpsd -V
gpsd: 3.18~dev (revision release-3.17-21-g7e7c547)
Then I ran xgps, and it got a good fix.
I also captured packets on the loopback interface and found that xgps uses the socket to talk to gpsd because there were traffic to or from port 2947.
Afterwards, I compiled and ran the code you sent to me in your last email.
However, I got nothing at the terminal, not even the "no GPS data available".
I uninstalled and re-installed the gpslib-dev (with sudo apt-get commands), still the same result.
One more strange thing is, when I ran the code using socket to talk to gpsd,
I could not get the coordinates either.
What do you think is the possible problem?
Thanks a lot~