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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:47:21+00:00 2026-05-22T16:47:21+00:00

This is my first question here, I’m going to try and give as much

  • 0

This is my first question here, I’m going to try and give as much info as I can.

I have a local installation of Apache 2.2 installed on my PC. I have it default to bind to port 100 (Don’t ask me why). When I run Apache, I cannot create a socket server with port of 100 because this port is already in use. What I want to do is duplicate this functionality in a Java Server I’m writing.

Currently, I create a socket server like this:

ServerSocket srv = new ServerSocket(100);

The problem is, this doesn’t block other applications from using this port. I can run more then one copy of my Java application, or even start my Apache server after this. I want the java Server Socket to mimic the behaviour of Apache and block other applications from binding to the chosen port.

I tried using Google, and the only thing I could find was this http://www.dreamincode.net/forums/topic/124376-block-port/ which implies that creating a socket server as shown above should block the port from use in other applications.

I’m using Windows 7 Ultimate-64bit, NetBeans IDE 6.9.1, and Java 1.6.0_23.

Thanks user658991,

It appears that the port will not be blocked until after a client connects or unless I call ServerSocket.accept();

try
{
    ServerSocket server = new ServerSocket(12345);
    System.out.println("Socket Server Established on port " + server.getLocalPort());
    server.accept(); // Code Stops here until connection is completed. 

    // Do Stuff
}
catch(IOException e)
{
    System.out.println("Socket Server Connection Failed!");
    System.out.println(e);
    System.exit(-1);
}
  • 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-22T16:47:22+00:00Added an answer on May 22, 2026 at 4:47 pm

    Are you absolutely sure your program is running? I guess it might have finished running. Please post your complete code. The code below should surely block the port.

    ServerSocket server = new ServerSocket(3000);
    
    while(true){
        Socket socket = server.accept();
        socket.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here. I have a notepad app that you can
First question here and can I start by saying how much help this site
this is my first question here so I hope I can articulate it well
Greetings to all! This is my first question here on stackoverflow. I have a
this is my first question.. so, here we go. i have a site, 100%
Sorry, this's my first time to ask a question here. So, I don't have
this is my first time posting here, I have a question which I have
This is my first question here :) I have an array with a number
Hey stackoverflow - This is my first question here. I have 2 tables in
this my first question on here. I hope someone can help. It is to

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.