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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:01+00:00 2026-05-26T08:33:01+00:00

I have Java console app, which i want to control from another computer. I

  • 0

I have Java console app, which i want to control from another computer. I use Socket class to send data through net and pipeline to connect the remote controlled program with Sender and Reader program, as shown:

Reader:

import java.io.*;
import java.net.*;
  public class Reader {
  //reads information from the remote controlled program
  public static void main(String[] args) throws Exception {
    Socket s = new Socket(args[0], Integer.parseInt(args[1]));
    PrintWriter bw = new PrintWriter(s.getOutputStream(), true);
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String vstup;
    do {
        vstup = in.readLine();
        if(vstup==null) break;
        bw.println(vstup);
    } while(true);
    s.close();
  }
}

Sender:

import java.io.*;
import java.net.*;
public class Sender {
  //sends instruction to the remote controlled program
  public static void main(String[] args) throws Exception {
    Socket s = new Socket(args[0], Integer.parseInt(args[1]));
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String vstup;
    do {
        vstup = in.readLine();
        if(vstup==null) break;
        System.out.println(vstup);
    } while(true);
    s.close();
  }
}

RemoteController:

import java.net.*;
import java.io.*;
public class RemoteController {
  public static void main(String[] main) throws IOException {
    ServerSocket ss = new ServerSocket(Integer.parseInt(main[0]));

    System.out.println("Done, please connect the program.");
    Socket reader = ss.accept(); //reads what the program says
    System.out.println("reader connected");
    Socket writer = ss.accept(); //writes into the program
    System.out.println("writer connected");

    BufferedReader read = new BufferedReader(new InputStreamReader(reader.getInputStream()));
    PrintWriter write = new PrintWriter(writer.getOutputStream(), true);

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    for(int i = 0; i<5; i++) {
        write.println(br.readLine());
        System.out.println(read.readLine());
    }

    write.close();
    read.close();
    writer.close();
    reader.close();
    ss.close();
  }
}

now i run the Remote controller and then i write

java Sender localhost 1234 | java SomeProgram | java Reader localhost 1234

into a comand prompt to test whenever it works. It sometimes works, sometimes not, any advise how to make it work everytime?

  • 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-26T08:33:01+00:00Added an answer on May 26, 2026 at 8:33 am

    All the problem was that the Sender and Reader programms conected in a random order to the main program, so adding Thread.sleep(200) resolved my problem, sorry for annoying.
    PS: If you program in java (and cmd), try it, iť really fun i think.

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

Sidebar

Related Questions

I have a java console app that I'm writing, and I want people to
I already have Java code to display and process data from a database. I
I have a Java console application that is launched from a batch script in
I have simple java app that prints `hello world!' on console. It is packed
We have a java app which we call with a parameter (a selected folder),
i have written a java program which currently runs as a desktop app, it
I have a .net app that needs to spawn a console process (a java
I have Java Map (out of Strings and Ints) objects that I want to
I want to have java script clicking a link on the page..I found something
Since JavaScript is not derived from Java, why does it have Java in the

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.