You don't have to use any programming to use SimpleServer. All it could
do is launch a program for a set time period, then close the program it launched.
That itself has some uses. The intended use of SimpleServer is to "talk"
to it from a web page. You will have to use a programming language like PHP,
perl, java, ASP, etc. to communicate with SimpleServer,
or use the included program, SimpleClient.exe, without the need
of a web page or any programming. Included are some PHP code examples below
and full example web pages in the programs folder, that
you are free to use and modify. SimpleClient.exe is also located in the
programs folder. It was written to easily test SimpleServer's
ability to pass a string of text, or arguments, to the program it launches,
mainly batch files and Microsoft
Windows Script files.
NOTE: Pressing SimpleServer's "Start Now" button will
launch the program without passing any arguments.
[ top ]
Let's write a batch file named, "test1.bat", that takes an argument. To make it simple, put the batch file in the same directory that "SimpleServer.exe" is. Refer to the batch file page on how to create a batch file. Copy the text in the box below to the batch file. in this case we will be passing the one word argument, "restart". The batch file will find it in the "%1" variable. Had we passed it the string "one two", "%1" would contain "one" and "%2" would contain "two".
| test1.bat |
|---|
@echo off rem title test if "%1" == "" goto error if "%1" == "exit" goto exit if "%1" == "restart" goto restart :error @echo Syntax error! Expecting: "test.bat exit" or "test.bat restart" goto end :exit @echo Exiting Windows... goto end :restart @echo Restarting Windows... :end pause |
When SimpleServer runs "test2.bat", the calculator or notepad can be launched depending on what argument is passed to it.
| test2.bat |
|---|
@echo off if "%1" == "calc" goto calc if "%1" == "notepad" goto notepad goto error :calc Start calc exit :notepad Start notepad exit :error @echo Syntax error! Expecting: "calc" or "notepad" on the command line! pause exit |
Let's write a ".vbs" file named, "test.vbs", that takes arguments. To make it simple, put the file in the same directory that "SimpleServer.exe" is. When "test1.vbs" is run, all it does is display the arguments passed to it.
| test1.vbs |
|---|
Dim arg
If WScript.Arguments.Count = 0 Then
WScript.Echo "no argument on the command line."
Else
For each arg in WScript.Arguments
WScript.Echo "arg : " & arg
Next
End If
|
When SimpleServer runs "test2.vbs", the calculator or notepad can be launched depending on what argument is passed to it.
| test2.vbs |
|---|
Dim WshShell, oExec, arg
If WScript.Arguments.Count = 1 Then
Set WshShell = CreateObject("WScript.Shell")
Set arg = WScript.Arguments
If arg.Item(0) = "calc" Then
Set oExec = WshShell.Exec("calc")
WScript.Quit(0)
Else
If arg.Item(0) = "notepad" Then
Set oExec = WshShell.Exec("notepad")
WScript.Quit(0)
End If
End If
End If
WScript.Echo "One argument is required on the command line." & vbCrLf &_
"Expecting: 'calc' or 'notepad'"
|
If SimpleServer is running, shut it down before proceeding. To set SimpleServer to use an argument, you can edit its ".ini" file, "SimpleServer.ini", or check the checkbox on the config dialog. If you would prefer to make the changes manually, follow these instructions... Don't change the "[Data]" line or anything left of the "=" characters. If you really mess up the ".ini" file, delete it. The next time you run SimpleServer, press the "Config" button. When you press the "Save" button, a "SimpleServer.ini" file will be created.
Let's look at the ".ini" file line by line.
|
![]() |
Restart SimpleServer. It will now be set to send the second line of text it receives to the program it launches, in this case, our batch file. If it errors and complains about another program is listening on the port you chose, press the "Config" button and change it to another number. Then change SimpleClient to that port. Make sure SimpleServer is listening on the same port that SimpleClient is set to send to.
We are ready to test it now. Press SimpleClient's "Send" button. The batch file should run.
Troubleshooting...
SimpleServer is listening on a user defined port on your computer. To communicate with it, you need to open a TCP socket connection to your computer's IP address at that port. Below is the simplest PHP code to accomplish this:
| connect.php |
|---|
<?
|
If you want the easiest way to communicate with SimpleServer
from a web page, look at the sample form page.
Other code examples and sample web pages can be found in the programs
folder.
[ top ]
[ << The start page. | The batch file page >> ]