Old 18th August 2005, 22:48   #1
jlee
Junior Member
 
Join Date: Aug 2005
Posts: 4
Question 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?
jlee is offline   Reply With Quote
Old 19th August 2005, 10:44   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 22nd August 2005, 09:01   #3
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
Maybe this thread can be useful for you :

http://forums.winamp.com/showthread....ghlight=socket

Best Regards.
kike_velez is offline   Reply With Quote
Old 22nd August 2005, 16:35   #4
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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
grahama is offline   Reply With Quote
Old 24th August 2005, 09:29   #5
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
Sorry Grahama but I don´t understand what do you want. Can you explain a litle more ?

Best Regards
kike_velez is offline   Reply With Quote
Old 24th August 2005, 11:09   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Not sure if this is what you want?
http://cpp.enisoc.com/articles/ip2host/

-Stu
Afrow UK is offline   Reply With Quote
Old 24th August 2005, 17:07   #7
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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
grahama is offline   Reply With Quote
Old 25th August 2005, 09:21   #8
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
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 is offline   Reply With Quote
Old 25th August 2005, 14:38   #9
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
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 :
PHP Code:
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
Attached Files
File Type: txt serverwithsockets.txt (3.4 KB, 353 views)
kike_velez is offline   Reply With Quote
Old 26th August 2005, 01:47   #10
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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 is offline   Reply With Quote
Old 26th August 2005, 01:58   #11
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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 is offline   Reply With Quote
Old 26th August 2005, 02:09   #12
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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
grahama is offline   Reply With Quote
Old 26th August 2005, 09:14   #13
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
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 ?
kike_velez is offline   Reply With Quote
Old 26th August 2005, 16:42   #14
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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 is offline   Reply With Quote
Old 26th August 2005, 19:12   #15
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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
grahama is offline   Reply With Quote
Old 29th August 2005, 09:38   #16
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
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
kike_velez is offline   Reply With Quote
Old 30th August 2005, 04:22   #17
grahama
Senior Member
 
Join Date: Sep 2004
Location: Los Angeles
Posts: 223
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
grahama is offline   Reply With Quote
Old 30th August 2005, 12:07   #18
kike_velez
Member
 
Join Date: Jun 2004
Location: Barcelona
Posts: 57
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:

PHP Code:
Section "server" server

          push 
"127.0.0.1"
          
push "8180"
          
Call ServerReceivedAndSend
         
SectionEnd 
Note : no errors treatment¡¡
Attached Files
File Type: txt serverreceivedandsend.txt (4.3 KB, 336 views)
kike_velez is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump