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

  • Home
  • SEARCH
  • 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 8433309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:21:07+00:00 2026-06-10T06:21:07+00:00

Part of a Java program I’m creating needs to talk to a service on

  • 0

Part of a Java program I’m creating needs to talk to a service on a remote machine. That remote machine is running a service (written in Delphi I believe) on a Windows platform.

I need to connect to that machine, send command strings and receive (String) responses.

If I connect using Linux CLI telnet session I get responses as expected:

[dafoot@bigfoot ~]$ telnet [host IP] [host port]
Trying [host IP]...
Connected to [host IP].
Escape character is '^]'.
Welcome to MidWare server
ping
200 OK
ProcessDownload 4
200 OK 

In the above the lines ‘ping’ and ‘ProcessDownload 4’ are me typing in the terminal, other lines are responses from remote system.

I created a Main in my Java class that will do the work to call the appropriate methods to try and test this (I’ve left out irrelevant stuff):

public class DownloadService {
    Socket _socket = null; // socket representing connecton to remote machine
    PrintWriter _send = null; // write to this to send data to remote server
    BufferedReader _receive = null; // response from remote server will end up here


    public DownloadServiceImpl() {
        this.init();
    }

    public void init() {
        int remoteSocketNumber = 1234;
        try {
            _socket = new Socket("1.2.3.4", remoteSocketNumber);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(_socket !=null) {
            try {
                _send = new PrintWriter(_socket.getOutputStream(), true);
                _receive = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }       
    }
    public boolean reprocessDownload(int downloadId) {
        String response = null;
        this.sendCommandToProcessingEngine("Logon", null);
        this.sendCommandToProcessingEngine("ping", null);
        this.sendCommandToProcessingEngine("ProcessDownload",     Integer.toString(downloadId));
        try {
            _socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    private String sendCommandToProcessingEngine(String command, String param) {
        String response = null;
        if(!_socket.isConnected()) {
            this.init();
        }
        System.out.println("send '"+command+"("+param+")'");
        _send.write(command+" "+param);
        try {
            response = _receive.readLine();
            System.out.println(command+"("+param+"):"+response);
            return response;
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        return response;
    }
    public static void main(String[] args) {
        DownloadServiceImpl service = new DownloadServiceImpl();
        service.reprocessDownload(0);
    }


}

As you will see in the code, there are a couple of sys.outs to indicate when the program is attempting to send/receive data.

The output generated:

send 'Logon(null)'
Logon(null):Welcome to MidWare server
send 'ping(null)'

So Java is connecting to the server ok to get the “Welcome to Midware” message back, but when I try to send a command (‘ping’) I don’t get a response.

So the questions:
– does the Java look about right?
– could problem be related to character encoding (Java -> windows)?

  • 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-06-10T06:21:09+00:00Added an answer on June 10, 2026 at 6:21 am

    You need to flush the output stream:

    _send.write(command+" "+param+"\n"); // Don't forget new line here!
    _send.flush();
    

    or, since you create a auto-flushing PrintWriter:

    _send.println(command+" "+param);
    

    The latter has the disadvantage that the line end can be \n or \r\n, depending on the system on which your Java VM runs. So I prefer the first solution.

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

Sidebar

Related Questions

I'm creating a windows service program which invokes a java program. Here is part
I have written a java program that tests the speed of a couple of
I've been asked (as part of homework) to design a Java program that does
I'm trying to get command line input into a running java program that I
I'm trying to migrate an existing actionscript program (server part) to java (red5). However,
I have written provider part in java. Notification is sent to the APNs. Not
i'm currently creating a database program in java and i am a bit stuck
I have a Java program that uses OAuth for communication with a server to
This issue is related to running a Java program (jar) dependent on thirdparty jar
I know how to use $.each in my program which is written in Java

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.