- NSIS Discussion
- Port Testing
Archive: Port Testing
jlee
18th August 2005 22:48 UTC
Port Testing
I have succesfully made an installer, but it lacks robustness. Now I would like to test to see if ports are in use, and change the default config ports of the program I am installing if they are in use. Does anyone know of a way of testing if ports such as 3306, or 80 are being used by the "localhost" ( the installer is geared for a a windows machine), with NSIS?
Afrow UK
19th August 2005 10:44 UTC
grahama was trying to do a similar thing in this topic:
http://forums.winamp.com/showthread.php?threadid=221461
Except there's no plugin to do this kind of thing. I'm not sure if grahama made the plugin either.
Are there any DOS tools you can use?
Try searching Google.
-Stu
kike_velez
22nd August 2005 09:01 UTC
Maybe this thread can be useful for you :
http://forums.winamp.com/showthread....ghlight=socket
Best Regards.
grahama
22nd August 2005 16:35 UTC
I am using tcpvcon to test for port communication...but have since moved on to more pressing issues...
/
tcpvcon is a pretty small command line tool NSIS can extract and control in the background. I settled on tcpvcon because it can get the process and specific port communication. You will have to include it in your NSIS exe as it does not come with Windows like netstat. Netstat can not get the process number, btw. I'd be very happy if someone proved me wrong.
/
Here is the command I used called every 1/2 second or so from NSIS:
tcpvcon -anc 828 | find /c "8181"
/
'828' is the process number of your app which NSIS can find for you. Then, just do a common [98/2000/XP] windows 'find' for the port and you are done :)
If the returned string is "1", port 8181 is being used by your process.
/
I wanted to use this to get the url string too [like http://127.0.0.1:8181?cmd=some_cmd], but initial research proved pretty fruitless. Anyone know how to do this ? Please let me know! Wonder if tcpvcon could be converted into a NSIS plugin... Anyway, it works very well for what it is.
/
hope this helps
g
kike_velez
24th August 2005 09:29 UTC
Sorry Grahama but I don´t understand what do you want. Can you explain a litle more ?
Best Regards
Afrow UK
24th August 2005 11:09 UTC
Not sure if this is what you want?
http://cpp.enisoc.com/articles/ip2host/
-Stu
grahama
24th August 2005 17:07 UTC
thanks guys :)
;
I want myNSISInstaller and myApp to communicate on the same computer by sending http requests to localhost.
;
Both myNSISInstaller and myApp are listening for any port communication on 8181. Http requests sent look something like:
http://127.0.0.1:8181?command2NSIS=doSomething
http://127.0.0.1:8181?command2myAPP=doSomething
;
Unfortunately, myApp can only communicate by sending out http requests. Pretty limiting :( Great for database stuff...bad for inter app communication. I need sockets but am at the mercy of myApp's platform.
;
So, if my app sends out local host port 8181:
http://127.0.0.1:8181?cmd2NSIS=quit
;
I want NSIS to grab the entire url above including the GET request, cmd2NSIS=quit, and then QUIT
;
With tcpvcon controlled with NSIS, I can grab the process,my app, and the port, 8181. Unfortunately, I can not get the GET request.
Does that make more sense?
;
Afrow, as to the ip2host link
I have just started on the C++ road :) Maybe in several weeks, I'll be able to make use out of http://cpp.enisoc.com/articles/ip2host/
thanks
g
kike_velez
25th August 2005 09:21 UTC
Hello
@grahama :
I understand this :
You have one application made with nsis : myNSISInstaller. That is always listening on port 8181 ( I think that is a server)
And you have another application myApp listening on the same port 8181 . This is a server too.
Maybe I am wrong but I think that you can not have 2 servers listening on the same port.
Best Regards
kike_velez
25th August 2005 14:38 UTC
Hello
If you want a server here is.
This function is a server that wait until there´s a client conected. After that the server gets the conection string (see example).
In a section :
Section "server" serve
push "127.0.0.1"
push "8180"
Call ServerWithSockets
Pop$0
messagebox mb_ok "$0"
>SectionEnd
>
And you can do everything you want with $0.
If you don´t want to stop the server , it must be on a loop in the section.
I Hope this is what you are looking for.
Best Regards
grahama
26th August 2005 01:47 UTC
thanks for the script :)
unfortunately, it does not give me the url string either :(
On the plus side this could be a great alternative to including tcpvcon in the nsis installer.
;
A clue:
The compiled script DOES output: GET/HTTP/1.1
It DOES NOT output the actual GET request...which is ?cmd=helloworld
;
To recap, myApp is sending out the http request to localhost:
http://127.0.0.1:8181?cmd=helloworld
;
this script you sent detects everything but the actual url string and GET request...
;
the question becomes: How do you grab the GET Request too ?
;
many thanks, kike :)
grahama
26th August 2005 01:58 UTC
I am getting:
GET/HTTP/1.1 HOST:127.0.0.1 Range:bytes=0- Accept:*/* User-Agent: QuickTime (qtver=6.5.1,os=Windows NT 5.0ServicePack 4)
;
seems a bit like getting php's user environment variables.
so, how do I flag '?cmd=helloworld' too
;
thanks :)
grahama
26th August 2005 02:09 UTC
Also,
if I use myApp to send a http request to:
http://www.myserver.com/phpScript.php?cmd=helloworld
everything works fine and the GET works as advertised
;
when I switch to localhost, I start having problems
g
kike_velez
26th August 2005 09:14 UTC
Hello Grahama
Sorry if the script not run for you.
To do the test (because i don´t have a app to send https):
1º - I start the server
2º - The server wait for a client
3º - I use the IE like appp. And I write
http://127.0.0.1:8180?app2nsis=cmd (or similar)
4º - The server catch the petition and show (with a msgbox mb_ok ....) The string:
GET /?app2nsis=cmd HTTP/1.1 Accept ............
5º - The server stop.
Maybe I am doing something wrong or I don´t understand you (my level of english is not good ;-)).
Best regards
Note : do you have a Server Web runing on port 8180 ?
grahama
26th August 2005 16:42 UTC
wow :)
it works now :)Was a quirk in the way my app sends out http requests in local host
;
thanks so much....as I have been attacking this problem on and off for serveral weeks now
;
g
grahama
26th August 2005 19:12 UTC
Here is a question :)
;
Can your socket server work as a PHP alternative for localhost communication?
I could see this working as middleware for SQLite.
;
If I wanted to use your NSIS socket server to send info back to myApp...like PHP does...how would that work ? Is there some kind of 'echo' equivalent that sends info back to the app that sent the request ?
;
thanks for all of your help, kike :)
g
kike_velez
29th August 2005 09:38 UTC
Hello
Well Grahama you must think that this is a basic,basic,basic server. Maybe you need something better than my basic server ;-)
Another question is if the server may received/send information. I think that is posible but with some changes.
I supose that you don´t need an echo server but a server that sends diferent information for diferent information received. I am wrong?
Best Regards
grahama
30th August 2005 04:22 UTC
myApp is correctly sending commands to myNSISServer thru your socket :)
I wanted to see if it were possible to have myNSISServer send info back to myAPP... like a php script would do.
In PHP, you can use something like:
if(messageSent2Me){
echo "I'm sending a message back to you";
}
As far your socket server, what would be the proper way to send info back ? Is this possible within the confines of your basic,basic,basic server ?
You have this function call for Receiving:
System::Call 'ws2_32::recv(i $4,t .R3,i 256,i 0)i .R2'
;
Is there a similar function for SENDING in ws2_32 ?
I saw this from msdn: http://msdn.microsoft.com/library/de...ock/send_2.asp
//-----------------------------------------
// If data has been received, echo the received data
// from DataBuf back to the client
if (WSASend(AcceptSocket, &DataBuf, 1, &RecvBytes, Flags, &AcceptOverlapped, NULL) == SOCKET_ERROR)
printf("WSASend() is busted\n");
;
C++ is not yet my strong suite...although I am doing my homework on the subject
;
many thanks for all of your help, kike :)
g
kike_velez
30th August 2005 12:07 UTC
Hello Grahama :)
This Basic Server can do:
Initialize WSA.
Create a socket.
Bind the socket.
Listen on the socket.
Accept a connection.
Receive data.
Send data to the client ----> Call ServerSendDataToClient
Disconnect.
I separate with two functions:
- ServerReceivedAndSend: This function wait for a client conection and call to the ServerSendDataToClient funtion and disconnect .(is like the ServerWithSockets function with the Call to ServerSendDataToClient )
- ServerSendDataToClient: This function is an example of how you can send data to the client. This function must be modified with your preferences. This is only a basic example.
The way to call in a section is:
Section "server" server
push "127.0.0.1"
push "8180"
Call ServerReceivedAndSend
SectionEnd
>
Note : no errors treatment¡¡