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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:34:50+00:00 2026-06-12T08:34:50+00:00

I used ServerSocket in java to check whether the mysql is running or not

  • 0

I used ServerSocket in java to check whether the mysql is running or not . If it’s not running I prompted the user to please run your mysql server . But , Some of my users complained we got error message although the mysql is running . It only happens in macos . What I find is .

Java Code :

public static boolean isPortFree(int port)
{
    if(port <= 0)
    {
        return false;
    }
    ServerSocket sock = null;
    try
    {
        String bindAddress = System.getProperty("bindaddress", "127.0.0.1");
        sock = new ServerSocket(port,0,InetAddress.getByName(bindAddress));
    }
    catch(Exception ex)
    {
        return false;
    }
    finally
    {
        if (sock != null)
        {
            try
            {
                sock.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }
    return true;
}

If i set system property bindaddress to localhost it returns false same i set to 127.0.0.1 returns true .
localhost , 127.0.0.1 is same why it behaves like this . It only occurs in macos . I think it’s not a my.cnf bindaddress problem . Because I checked in command prompt with

 mysql -uroot -hlocalhost
 mysql -uroot -h127.0.0.1

both are works .

Netstat

MacOs

 tcp4       0      0  *.3306                 *.*                    LISTEN

Other Os

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN 

Is there any difference between tcp4 and tcp?

Any Idea why it happens ?

  • 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-12T08:34:52+00:00Added an answer on June 12, 2026 at 8:34 am

    The two examples are effectively binding to different interfaces: INADDR_ANY does not prevent binds to specific adapters.

    It will work as expected if on OSX MySQL was configured exactly the same as your reported ‘Other Os‘.

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

Sidebar

Related Questions

I used Jquery to insert a variable to div. Please check my code. var
I'm implementing a java TCP/IP Server using ServerSocket to accept messages from clients via
Used XStream lib, but no children XML was difficult to parse in Java. Wanting
I have used server socket concept in java to transfer files like images and
I used a simple fork() to simulate client / server then a very simple
I have written code for server and client sockets. I have used threads using
I'm trying to make a simple http client server using java. It will show
Okay so I'm trying to learn Java client/server stuff, and am going through the
I have an in-house HTTP server written in Java; full source code at my
Is there anything, what can block me using the java.net.ServerSockets on the Tomcat server?

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.