Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:02:28+00:00 2026-05-22T13:02:28+00:00

I have an app in android which is a kind of client-server. I’ve established

  • 0

I have an app in android which is a kind of client-server.

I’ve established the connection between those two and now I’m sending data through the socket.

The server is the one who sends the data and the client reads it from the socket.

The server sends to socket some GPS data (longitude,latitude) and for really sending it I’m using 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 every longitude and latitude that I wanna send I add a workerID which is an int.

So finally through my socket I’m sending an instance of the Coordinate class.

   Coordinate coord=new Coordinate(lat,lon,workerID);
   os=new PrintStream(clientSocket.getOutputStream());

    os.println(coord);

Well,until here everything goes fine.

On the client side I’m reading the data this way:

Scanner is=new Scanner(new DataInputStream(socket.getInputStream()));

while(is.hasNext())
            {
                try{
                Coordinate coord=is.next();
                    System.out.println(coord.getLon());

                    }
                catch(Exception e){
                    e.printStackTrace();
                }
            }

The problem is that Scanner class that I’m using it for reading from the socket input stream returns String,but what I’m sending through the socket is something completly different……

Does someone knows how could I convert the input data to Coordinate or how should I proceed to find the latitude and longitude from what I’m sending through the socket?????

Thx!

EDIT:I’m using that format because I have my needs with that data!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T13:02:29+00:00Added an answer on May 22, 2026 at 1:02 pm

    os.println(coord) is just writing a reference, which doesn’t make much sense, if you want to send something meaningful then the Coordinate class should implement Serializable. Have a look at this article where it is explained.

    Optionally I recommend you to dump and load at both ends using the JSON format. It will provide you an easy and readable way to inter-operate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android app which needs to play a sound resource on a
I have an application for Android which communicates with a Google App Engine (GAE)
I have an app with a large ListView which is terribly slow so I'm
I have an app which could benefit from the user being able to choose
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd
I have a simple question. I am trying to design a simple Android app,
I have a python app running fine on Windows, Linux and Mac which I
I have a new earthquake notification android app thats in it's initial release version.
I'm writing an android app and in it I want to have a sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.