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 3602156
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:42:39+00:00 2026-05-18T20:42:39+00:00

Here is my goal. I am designing a server that will spit out data

  • 0

Here is my goal. I am designing a server that will spit out data every second. I need to also design a client (on android) that will connect to that server and gather the data that is being sent by the server. I have already wrote up some code for this in java and for the android. However, my experience with java and android is very minimal. I have been having a lot of difficulty with this but have started making progress. I was wondering if everyone could take a look at my code and give some tips on how to best perform this design.

The server will just be constantly spitting out data and the client will connect to the server and then start gathering the data that is being sent.

The data that is being sent is not important. Right now it will just be something random for testing.

Thanks in advance!

THE JAVA SERVER

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.net.ServerSocket;

import java.net.Socket;





public class SmartServerSocket {

    private ServerSocket server;

    private int port = 7777;



    public SmartServerSocket() {

        try {

            server = new ServerSocket(port);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    public static void main(String[] args) {

        SmartServerSocket smart = new SmartServerSocket();

        smart.handleConnection();

    }

    public void handleConnection() {

        // TODO Auto-generated method stub

        System.out.println("Waiting for client message...");

        while (true) {

            try {

                Socket socket = server.accept();

                new ConnectionHandler(socket);

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

    }

}

class ConnectionHandler implements Runnable {

    private Socket socket;

    public ConnectionHandler(Socket socket) {

        this.socket = socket;

        Thread t = new Thread(this);

        t.start();

    }

    public void run() {

        ObjectOutputStream oos = null;

        int test = 0;

        try {

            while(true)

            {

                oos = new ObjectOutputStream(socket.getOutputStream());

                oos.writeObject(Integer.toString(test));

                test++;

                System.out.println("Waiting for client message...");

            } 

        } catch (IOException e) {

                e.printStackTrace();

        } finally {

            try {

                    oos.close();

                    socket.close();

                } catch (IOException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

                }



            }

        }

    }




THE ANDROID CLIENT
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

//import android.app.Activity;

public class ConnectDevice implements Runnable {
    public void run(){
        try {
            System.out.println("test1");
            //InetAddress host = InetAddress.getLocalHost();
            InetAddress host = InetAddress.getByName("THEIPADDRESS");
            Socket socket = new Socket(host.getHostName(), 7777);
            System.out.println("test2");
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            System.out.println("test3");
            String message = (String) ois.readObject();
            System.out.println("test4");    
            System.out.println("Message: " + message);

            ois.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
  • 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-18T20:42:40+00:00Added an answer on May 18, 2026 at 8:42 pm

    I’m using Apache Mina to handle my game’s connection. You should take a look on it. It have really made my life easier.

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

Sidebar

Related Questions

I need to add some function that returns a value to a dom element.
My goal here is to override a method if it isn't found, otherwise use
So to give a little context, my goal here is to produce a binary
having a bit of a problem with a recent project. The goal here is
I'm working on a internal web application (only employees can log in) and need
I have a bunch of legacy documents that are HTML-like. As in, they look
I would like to insert a parameter value found the url into my javascript
In searching I came across ASP.NET MVC page/subpage routing and the wildcard was somewhat
Hei guys i have this JQuery Ajax call from my view and it looks
If I had a normal website this would be a simple enough fix... but

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.