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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:17:04+00:00 2026-05-15T06:17:04+00:00

A while ago I developed a little LAN chat app. in Java which allows

  • 0

A while ago I developed a little LAN chat app. in Java which allows chatting with other hosts, send images, etc. Although it was created just for fun, now it’s being used where I work.

Currently, there is no “chat server” on the app. where each client registers, updates it’s status, etc. (I liked the idea of symmetric design and not depending on a server running on some other machine).

Instead, each host is a client/server which has a hosts.properties file with the hostname of the other hosts, and – for instance – broadcasts to each one of them when sending a massive message/image/whatever.

In the beginning there were just a couple of hosts, so this hosts.properties file wasn’t an issue. But as the amount of users increased, the need of updating that file was a bit daunting. So now I’ve decided to get rid of it, and each time the app. starts, dynammically find the other active hosts.

However, I cannot find the correct way of implement this. I’ve tried starting different threads, each one of them searching for other hosts in a known range of IP addresses. Something like this (simplified for the sake of readability):

/** HostsLocator */
public static void searchForHosts(boolean waitToEnd) {
    for (int i=0; i < MAX_IP; i+= MAX_IP / threads) {
        HostsLocator detector = new HostsLocator(i, i+(MAX_IP / threads - 1)); // range: from - to
        new Thread(detector).start();                 
    }
}

public void run() {
    for (int i=from; i<=to; i++)
        findHosts( maskAddress + Integer.toString(i) );
}

public static boolean findHosts(String IP) {
    InetAddress address = InetAddress.getByName(IP);
    if ( address.isReachable(CONNECTION_TIME_OUT) )
        // host found!
}

However:

  • With a single thread and a low value in CONNECTION_TIME_OUT (500ms) I get wrong Host Not Found status for for hosts actually active.
  • With a high value in CONNECTION_TIME_OUT (5000ms) and only one single thread takes forever to end
  • With several threads I’ve also found problems similar like the first one, due to collisions.

So… I guess there’s a better way of solving this problem but I couldn’t find it. Any advice? Thanks!

  • 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-15T06:17:04+00:00Added an answer on May 15, 2026 at 6:17 am

    You could try UDP Broadcast to a specific port. All running instances of your app on the network could listen to that port and then respond with a message identifying them as a host.

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

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 429k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer strerror() returns a char* on windows so you need a… May 15, 2026 at 1:29 pm
  • Editorial Team
    Editorial Team added an answer Try this: Dim found as Boolean = false For Each… May 15, 2026 at 1:29 pm
  • Editorial Team
    Editorial Team added an answer You could try something like this: http://jsfiddle.net/5sYFT/1/ var text =… May 15, 2026 at 1:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.