• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

hook a port

how can I detect when a port (winsock) is used and depending of situation close the port.
0
twineMAN
Asked:
twineMAN
  • 4
1 Solution
 
EpsylonCommented:
You can detect if the port is available by opening it yourself. If it fails the port is in use.

It is impossible to close a port that is being used by another program.

Epsylon.
0
 
EpsylonCommented:
Put a ServerSocket on your form and try this code:

  ServerSocket1.Port := yourport;
  try
    ServerSocket1.Active := true;
  except
    ShowMessage('Port is in use');
  end;

Epsylon.
0
 
maharaCommented:
that's it, i think...
0
 
EpsylonCommented:
Well, since twineMAN is not responding.....
0
 
EpsylonCommented:
It is impossible to close a port that is being used by another program.

You can detect if the port is available by opening it yourself. If it fails the port is in use.
Put a ServerSocket on your form and try this code:

  ServerSocket1.Port := yourport;
  try
    ServerSocket1.Active := true;
  except
    ShowMessage('Port is in use');
  end;
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now