Sign in to follow this  
Followers 0
caocao81

Need help for how to know which program use the port

4 posts in this topic

#1 ·  Posted (edited)

I want to write a program to check port conflicts(a program I use the port 9000 and 9001,before the program run, I want to check the port 9000 and 9001 if is using), a part of program is follow,when port conflicts, I want to tell user which program is using port 9000 or 9001, now I have no idea for to get the port conflicts program name, some one can

help me? thanks a lot!

Func CRMPortCheck()
    
    $Server = @IPAddress1
    $CRMPort1 = "9000"
    $CRMPort2 = "9001"

    TCPStartUp()

    $Socket1 = TCPConnect( $Server, $CRMPort1 )
    $Socket2 = TCPConnect( $Server, $CRMPort2 )

    If ($Socket1 = -1) And ($Socket2 = -1) Then 
        Return 0
    Else 
        TCPCloseSocket ($Socket1)
        Return 1
    EndIf

EndFunc
Edited by caocao81

Share this post


Link to post
Share on other sites



You can send a string with the program name upon connect.

could you go into a little more detail about it ?

Share this post


Link to post
Share on other sites

In your server application, when someone connects to you, send a string identifying the server.

While 1
$ConnectedSocket = TCPAccept( $MainSocket)
If $ConnectedSocket >= 0 Then
    _addclient() ; whatever you do to add the client to a list of clients
    TCPSend($ConnectedSocket, "I am program 1")
    exit
EndIf
Wend

Then on the connecting end (client):

Func CRMPortCheck()
    
    $Server = @IPAddress1
    $CRMPort1 = "9000"
    $CRMPort2 = "9001"

    TCPStartUp()

    $Socket1 = TCPConnect( $Server, $CRMPort1 )
    If Not @error Then Return TCPRecv($Socket1, 100)
    $Socket2 = TCPConnect( $Server, $CRMPort2 )
    If Not @error Then Return TCPRecv($Socket1, 100)
EndFunc

I hope you get the idea.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0