I have an application in Android that is a kind of client server.
I have established a connection between the two, and now I am sending data through a socket.
The server is the one who sends the data, and the client reads it from the socket.
The server sends some GPS data (longitude, latitude) to the socket to send it. I use the following format:
public class Coordinate {
private final double lon;
private final double lat;
private final int workerId;
public Coordinate(double lat, double lon, int workerId) {
this.lat = lat;
this.lon = lon;
this.workerId=workerId;
}
public double getLon() {
return lon;
}
public double getLat() {
return lat;
}
public int getwId(){
return workerId;
}
}
So, for each longitude and latitude that I want to send, I add the identifier workerID, which is an int.
So finally, through my socket, I send an instance of the Coordinate class.
Coordinate coord=new Coordinate(lat,lon,workerID);
os=new PrintStream(clientSocket.getOutputStream());
os.println(coord);
Well, until everything works out here.
On the client side, I read the data as follows:
Scanner = new scanner (new DataInputStream (socket.getInputStream ()));
while(is.hasNext())
{
try{
Coordinate coord=is.next();
System.out.println(coord.getLon());
}
catch(Exception e){
e.printStackTrace();
}
}
, Scanner, , String, , , - ...
- , Coordinate , ?????
!
EDIT: , .