Jump to content

Remote Server BETA


themax90
 Share

Recommended Posts

Okay so I have had requests for my remote server. All I have too do is add some user-defined functionality. However, you can do ANYTHING AutoIt can except use variables. Here is Remote Server BETA

Opt("RunErrorsFatal", 0)
Global Const $Port = 8000
Global $MaxConc = 100
Global $MainSocket = TCPStartServer($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")
Global Const $MaxLength = 512
Global $ConnectedSocket[$MaxConc]
Global $CurrentSocket = 0
Local $Track = 0
Global Const $MaxConnection = ($MaxConc - 1)
For $Track = 0 To $MaxConnection Step 1
    $ConnectedSocket[$Track] = -1
Next
While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
    If $ConnectedSocket[$CurrentSocket] <> - 1 Then
        $CurrentSocket = SocketSearch()
    EndIf
    $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            If $Data = "~bye" Then
                TCPCloseSocket($ConnectedSocket[$Track])
                $ConnectedSocket[$Track] = -1
                $CurrentSocket = SocketSearch()
            ElseIf $Data <> "" Then
                AutoItExecute($Data)
                TCPSendMessageAll($MaxConnection, $Data & " operated.")
            EndIf
        EndIf
    Next
WEnd
Func AutoItExecute($Cmd)
    RunWait(@AutoItExe & ' /AutoIt3ExecuteLine "' & $Cmd & '"')
EndFunc
Func SocketSearch()
    Local $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] = -1 Then
            Return $Track
        Else
        ; Socket In Use
        EndIf
    Next
EndFunc  ;==>SocketSearch
Func TCPSendMessageAll($ConnectionLimit, $Data)
    Local $Track = 0
    For $Track = 0 To $ConnectionLimit Step 1
        If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
    Next
EndFunc  ;==>TCPSendMessageAll
Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    Select
        Case $Socket = 0
            SetError(@error)
            Return -1
    EndSelect
    $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    Select
        Case $Socket = -1
            SetError(@error)
            Return 0
    EndSelect
    SetError(0)
    Return $Socket
EndFunc  ;==>TCPStartServer

You can use this as a client

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
Local $Server = InputBox("Server", "Please input the server you would like to connect to:")
Local $Port = InputBox("Server Port", "Please input the port or the server you would like to connect to:")
TCPStartup()
$MainSocket = TCPConnect(TCPNameToIP($Server), $Port)
If $MainSocket = -1 Then Exit MsgBox(0, "Error", "Could Not Connect or Bad Connection")
GUICreate("Server Client", 390, 210)
$Send = GUICtrlCreateEdit("", 10, 10, 175, 150, $WS_VSCROLL)
Local $History = GUICtrlCreateEdit("Server Messages:", 200, 10, 175, 150, BitOR($WS_VSCROLL, $ES_READONLY))
$SButton = GUICtrlCreateButton("Send", 145, 165, 100, 35)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $SButton Or _IsPressed ("0D") = 1 Then
        $Text = GUICtrlRead($Send)
        $TCPSent = TCPSend($MainSocket, $Text)
        GUICtrlSetData($Send, "")
    EndIf
    $Recv = TCPRecv($MainSocket, 512)
    If $Recv <> "" Then
        GUICtrlSetData($History, GUICtrlRead($History) & @CRLF & $Recv)
        _GUICtrlEditLineScroll ($History, 0, _GUICtrlEditGetLineCount ($History))
    EndIf
WEnd
Func OnAutoItExit()
    TCPCloseSocket($MainSocket)
    TCPShutdown()
EndFunc;==>OnAutoItExit

Just connect too the port and server ip and send any function!!! For example send

MsgBox(0, 'Title', 'Text') and a message box will appear. You CANNOT use double quotes ( " s ). There is no user or authentication system, neither is there much. I just would like you all too know I AM working on it. All I did was add about 4 lines of code too create this. Happy holidays :P

AutoIt Smith

P.S. I know there are many bugs in the code dealing with AutoIt functionality, but for simple functions it will work. This can be used for file management and other things. It is just a bored script :lmao:

Link to comment
Share on other sites

Please be tolerate of my lack of knowledge..

What if I wanted to add more custom commands, could I change the if then to a switch case system, and if so could anyone please provide an example.

Say mabe I wanted to add a "~reboot" commd in addiotion to the ~bye command (I don't need the ~reboot code, just the switch syntax)...

The section in the server code:

If $Data = "~bye" Then

And if no custom command is found, then run the code that the server currently does... ie

ElseIf $Data <> "" Then

AutoItExecute($Data)

TCPSendMessageAll($MaxConnection, $Data & " operated.")

EndIf

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Okay so I have had requests for my remote server. All I have too do is add some user-defined functionality. However, you can do ANYTHING AutoIt can except use variables. Here is Remote Server BETA

Cool, I like it

Link to comment
Share on other sites

why not just do this

Func TCPStartServer($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    If $Socket = 0 Then
        SetError (@error)
        return -1
    EndIf
    $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    If $Socket = -1 Then
        SetError(@error)
        Return 0
    EndIf
    SetError(0)
    Return $Socket
EndFunc ;==>TCPStartServer

?

arent all those select..case..endselects pointless?

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Actually I have tested the Select...Case environment and it works about 0.0019 faster then If, Else.... and it also allows you to test things differently with less Then and ElseIf <> Then stuff. It's just easier to script.

Link to comment
Share on other sites

  • 2 months later...

I have not been able to get the client code to work... I am using the AU3 beta version... here is my errors.....

C:\Program Files\AutoIt3\Include\GuiEdit.au3(75,21) : ERROR: IsHWnd(): undefined function.
   If IsHWnd($h_edit)
~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\GuiEdit.au3(202,36) : ERROR: DllStructCreate(): undefined function.
   Local $p = DllStructCreate($RECT)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\GuiEdit.au3(208,123) : ERROR: DllStructGetPtr(): undefined function.
      DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_edit, "int", $EM_GETRECT, "int", 0, "ptr", DllStructGetPtr($p)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\GuiEdit.au3(212,57) : ERROR: DllStructGetData(): undefined function.
   Local $array = StringSplit(DllStructGetData($p, $left)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\Misc.au3(84,50) : ERROR: DllStructGetSize(): undefined function.
    DllStructSetData ($p, 1, DllStructGetSize ($p)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Include\Misc.au3(84,51) : ERROR: DllStructSetData(): undefined function.
    DllStructSetData ($p, 1, DllStructGetSize ($p))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(19,61) : ERROR: TCPAccept(): undefined function.
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(26,65) : ERROR: TCPRecv(): undefined function.
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(28,56) : ERROR: TCPCloseSocket(): undefined function.
                TCPCloseSocket($ConnectedSocket[$Track])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(54,88) : ERROR: TCPSend(): undefined function.
        If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(59,26) : ERROR: TCPStartup(): undefined function.
    $Socket = TCPStartup()
~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3(65,56) : ERROR: TCPListen(): undefined function.
    $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\SEND Proj\server.au3 - 12 error(s), 0 warning(s)
Link to comment
Share on other sites

  • Moderators

You need AutoIt Beta: http://www.autoitscript.com/forum/index.ph...opic=19717&st=0

Most of us code using that... you'll want it to run most scripts on here.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 2 weeks later...

You cannot connect to 127.0.0.1 unless the server ip is set to "127.0.0.1", otherwise try connecting to your public ipaddress. Remember this must be ran without a router. If you cannot connect, then in most cases it is usually your ISP who has blocked traffic in that direction.

Link to comment
Share on other sites

  • 3 months later...

@AutoIt Smith

I like it. Very simular to the TCP Communicator (you created) and I modified as the base for the Client Commander I created. Did not think to use Autoit commands like that though, very cool!

4Fun

Link to comment
Share on other sites

  • 2 months later...

Hi AutoIt Smith,

I'd like to see if I understand this page correctly:

- I have put the server code in an .au3 file, compiled it into a .exe and executed it. It is now running in my systray.

- I have put the client code in a .au3 file and executed it as a script. I can connect to my PC using the hostname and port number 80.

- A Server Client window appears

- However, if i put "MsgBox(0, 'Title', 'Text')" and press the send button nothing happens. Should something happen at this point?

Thanks and regards,

Kev

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...