Jump to content

Remote Server BETA


themax90
 Share

Recommended Posts

  • 1 year later...

I took a look at the script posted by Smith, and tried it out.

I noticed that any command requiring double quotes did not work (and yes, I WAS using single quotes.)

I'm not sure if anyone else got this error, but I played around with it, and I made a quick edit. It works just fine now.

Server:

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)
    $cmd = binarytostring($cmd, 1)  ;Modification here, converts the binary back to a string to be executed.
    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

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)
    $text2 = stringtobinary($text, 1);Modification here, converts command into binary so that when it is sent, the single quotes aren't ACTUALLY there so they don't interfere.
        $TCPSent = TCPSend($MainSocket, $Text2)
        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

Hope this helps anyone who was having the same trouble as I was

Link to comment
Share on other sites

  • 1 year 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

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 :)

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 :)

hi Smith. Your script is great but i am still catching on learning it a bit because i'm new to AutoIt. but i have tested example in your collection and they work great as well.

is it possible that a client will connect not only to one server. i mean client has still option to look or to connect to any available server.

thank you.

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

wow above code looks complicated. How bout just look at autoit help file it will do the same thing as above. Check at function->Network Management->TCPRev for server part and TCPsend for client part. Too lazy then copy paste it will work perfectly. Oh why still not working then check your windows firewall or any self install firewall. If you using external ip (not start with 192.xxx.xxx.xxx) then please configure your router and make port fowarding. Then it will work. For starters better use 127.0.0.1 and port any number above 10000. It will work in the same machine (:x)

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...