Hey all,
So, I've been trying to learn a bit about programming for Android. I've got past "Hello, World!" and I've got GPS stuff to work.
I'm trying to have the device sit on a port and pipe GPS data over the port ( Eventually NEMA std, and have that talk with Marble for long drives )
It throws the I/O Error and Toast-s me "Ohh fuuuuu -- Can't create a GPS port on port 20017"
At first, I thought it was the port ( originally 2017 being normal user, might not have been able to create a reserved port ) but then I bumped it up to a very high number.
Here's what I've got so far:
public class GeoLoc extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener;
int port = 20017;
try {
mlocListener = new MyLocationListener( port );
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
} catch (IOException e) {
String Text = "Ohh fuuuuu -- Can't create a GPS port on port " + port;
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
}
...
SNIP
...
public class MyLocationListener extends Thread implements LocationListener {
ServerSocket s;
ArrayList<ServerThread> childs;
public MyLocationListener( int port ) throws IOException {
this.s = new ServerSocket( port );
this.start();
}
@Override
public void run() {
try {
String Text = "Waiting on port " + this.s.getLocalPort();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
Socket s = this.s.accept();
this.childs.add(new ServerThread( s ) );
} catch (IOException e) {
// crap-tastic but managable.
}
}
@Override
public void onLocationChanged(Location loc) {
for ( int i = 0; i < this.childs.size(); ++i ) {
this.childs.get(i).sendLoc(loc);
}
}
...
SNIP
...
}
}
Thanks, guys!