caocao81 Posted August 28, 2009 Share Posted August 28, 2009 (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 August 28, 2009 by caocao81 Link to comment Share on other sites More sharing options...
jvanegmond Posted August 28, 2009 Share Posted August 28, 2009 You can send a string with the program name upon connect. github.com/jvanegmond Link to comment Share on other sites More sharing options...
caocao81 Posted August 31, 2009 Author Share Posted August 31, 2009 You can send a string with the program name upon connect.could you go into a little more detail about it ? Link to comment Share on other sites More sharing options...
jvanegmond Posted August 31, 2009 Share Posted August 31, 2009 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. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now