Jump to content
Sign in to follow this  
Ruben

How to make a Basic local Autoit server for http requests?

Recommended Posts

Ruben

Hello, i'd like to know if anyone knows how to make a basic autoit localhost server that waits for HTTP post requests and process them like if it was a normal web server (without the mysql part)?

For example i have a game that allows players to send data via http requests (custom online scoreboards, player stats, etc) and i'd like to process those with autoit alone instead of using a wamp server and a php script to save that information on a txt file first so my autoit program can get that information by reading the file.

Thanks

Share this post


Link to post
Share on other sites
FireFox

Try >this, I never tested it so I can't give you any advice.

However it's not very difficult to make one (I did some).

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Ruben

Try >this, I never tested it so I can't give you any advice.

However it's not very difficult to make one (I did some).

Br, FireFox.

Thanks, i've already looked at it, is something similar but im looking for something even more basic, a simple server that does only one thing, detect's incoming http "post" packets and saves them in a variable or array that my program can use.

I just want to remove the middleman, the wamp server and php code,

Share this post


Link to post
Share on other sites
FireFox

Learn about HTTP headers and TCP functions (examples in the helpfile) and you're done.

Process the incomming data as you like.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Ruben

Learn about HTTP headers and TCP functions (examples in the helpfile) and you're done.

Process the incomming data as you like.

Br, FireFox.

I've already tried to find tutorials and stuff, but everything is about connecting to an already existing webserver, sending requests to a webpage or creating a tcp server/client... but none about making a localhost server that waits for HTTP requests.

I've tried tcp but i can't understand why it is so slow and sometimes even get's stuck

#include <GUIConstantsEx.au3>

Example()

Func Example()
   Local $szIPADDRESS = "127.0.0.1"
   Local $nPORT = 80
   Local $MainSocket, $edit, $ConnectedSocket, $szIP_Accepted
   Local $msg, $recv

   TCPStartup()
   $MainSocket = TCPListen($szIPADDRESS, $nPORT)
   If $MainSocket = -1 Then Exit

   GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 300, 100, 100)
   $edit = GUICtrlCreateEdit("", 10, 10, 280, 280)
   GUISetState()

   $ConnectedSocket = -1

   Do
      $ConnectedSocket = TCPAccept($MainSocket)
   Until $ConnectedSocket <> -1
   $szIP_Accepted = SocketToIP($ConnectedSocket)

   While 1
      $msg = GUIGetMsg()
      If $msg = $GUI_EVENT_CLOSE Then ExitLoop

      $recv = TCPRecv($ConnectedSocket, 1024)
      ;If $recv <> "" Then MsgBox(4096, "Test", $recv , 10)

      If @error Then
         ;MsgBox(4096, "error", @error, 10)
         Do
         $ConnectedSocket = TCPAccept($MainSocket)
         Until $ConnectedSocket <> -1
         ;$szIP_Accepted = SocketToIP($ConnectedSocket)
         ;ExitLoop
      EndIf

        ; convert from UTF-8 to AutoIt native UTF-16
        $recv = BinaryToString($recv, 4)
        If $recv <> "" Then GUICtrlSetData($edit, $recv & @CRLF & GUICtrlRead($edit))

    WEnd


    If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

    TCPShutdown()
EndFunc   ;==>Example

; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet

    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc   ;==>SocketToIP
Edited by Ruben

Share this post


Link to post
Share on other sites
FireFox

This old helpfile example is not made to do what you're trying to achieve.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Ruben

That's why i need help :)

Share this post


Link to post
Share on other sites
FireFox

-Listen on port 80

-Put the TCPAccept function in your loop

-In case this one succeed - new client - receive the data with the TCPRecv function

-Make some String operations to detect if it's a HTTP post request (POST /someurl HTTP 1.1) and so on.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×