Ruben Posted September 3, 2013 Share Posted September 3, 2013 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 Link to comment Share on other sites More sharing options...
FireFox Posted September 3, 2013 Share Posted September 3, 2013 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. Link to comment Share on other sites More sharing options...
Ruben Posted September 3, 2013 Author Share Posted September 3, 2013 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, Link to comment Share on other sites More sharing options...
FireFox Posted September 4, 2013 Share Posted September 4, 2013 Learn about HTTP headers and TCP functions (examples in the helpfile) and you're done.Process the incomming data as you like.Br, FireFox. Link to comment Share on other sites More sharing options...
Ruben Posted September 4, 2013 Author Share Posted September 4, 2013 (edited) 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 expandcollapse popup#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 September 4, 2013 by Ruben Link to comment Share on other sites More sharing options...
FireFox Posted September 4, 2013 Share Posted September 4, 2013 This old helpfile example is not made to do what you're trying to achieve. Link to comment Share on other sites More sharing options...
Ruben Posted September 5, 2013 Author Share Posted September 5, 2013 That's why i need help Link to comment Share on other sites More sharing options...
FireFox Posted September 5, 2013 Share Posted September 5, 2013 -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. 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