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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:52:24+00:00 2026-06-12T23:52:24+00:00

I have two Java applications, where an Android client connects to a server on

  • 0

I have two Java applications, where an Android client connects to a server on a computer and sends a message using BufferedWriter over websockets.

The client:

    try {
        toast("Sending...");
        Socket sock = new Socket(ip, PORT);
        OutputStream os = sock.getOutputStream();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        bw.flush();
        bw.write("Hello Server!");
        toast("Connected!");
    } catch (UnknownHostException e) {
        toast(e.getMessage());
    } catch (IOException e) {
        toast(e.getMessage());
    }

The server:

public static void main(String[] args) {
    ServerSocket server;
    ConnectionThread ct;
    Socket s;
    ExecutorService es = Executors.newSingleThreadExecutor();
    try {
        System.out.println("Starting server...");
        server = new ServerSocket(1337);
        s = server.accept();
        ct = new ConnectionThread(s);
        es.execute(ct);
    } catch (IOException ex) {
        ex.printStackTrace();
    }       
}

The ConnectionThread class:

public class ConnectionThread implements Runnable {
    private Socket sock;
    private InputStream is;
    private BufferedReader br;
    private boolean online;
    public ConnectionThread(Socket s) {
        System.out.println("Creating connection thread.");
        this.sock = s;
        online = true;
    }
    @Override
    public void run() {
        String input = "";
        try {
            System.out.println("Starting to read...");
            is = sock.getInputStream();
            br = new BufferedReader(new InputStreamReader(is));

            while (online) {
                input = br.readLine();
                if(input != null){
                    System.out.print("Received message: ");
                    System.out.println(input);
                }

            }

            br.close();
            is.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

When I run the server, and then the client, the client will show the “Connected!” toast, and the server’s output will be:

Starting server...
Creating connection thread.
Starting to read...

So, it seems like the connection is actually being made, but the message does not arrive. Does anybody know why this could be happening?

  • 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-12T23:52:25+00:00Added an answer on June 12, 2026 at 11:52 pm

    Your server is expecting a complete line terminated by a newline. Try:

    bw.write("Hello Server!");
    bw.newLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two my own applications on C++ and Java: server and client. It
I have two Java applications in my network that talk to each other over
I would like to create a server using .NET and Java client (Android application).
I have java two projects; one server project and one client project. In my
I have two separated applications, one written in Java and other in Erlang. Both
I have a android webservice client application. I am trying to use the java
I have been developing an Android/Java application that opens up two simultaneous Apache HTTP
I am a newbie to Android development. I have two Java files in my
I am Java beginner. I have developed only two Java desktop applications and I
I am working on android applications. In my application I am using two packages

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.