Jump to content

Recommended Posts

Posted

Hi.

I have a problem with this script...@IPAddress1 works fine but using _GetIP() causes an error.

#include <Inet.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_Singleton(@ScriptName)

Global $IP = _GetIP() , $Port = 80

TCPStartup()

$MainSocket = TCPListen($IP, $Port)

If $MainSocket = -1 Then
    MsgBox(0 , "", "Error?")
    Exit
EndIf

$ConnectedSocket = -1

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

While 1
        $Msg = GUIGetMsg()

        If $Msg = $GUI_EVENT_CLOSE Then
            If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
            TCPShutdown()
            ExitLoop
        EndIf

        $Recv = TCPRecv($ConnectedSocket, 2048)

        If $Recv = "Test" Then ConsoleWrite("Online")
WEnd
Posted

What do you mean by "causes an error"?

Do you get an error message? Does the script crash? ...

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

I don't know much about this, but I port fowarded port 8080 to my PC from my router thing, and modified your example a little and seemed to work :)

#include <Misc.au3>
#include <Inet.au3>

HotKeySet("{ESC}", "_Exit")

Global $IP = _GetIP() , $Port = 8080
TCPStartup()

If _Singleton("MainInstance", 1) = 0 Then
    Global $Server = TcpConnect($IP, $Port)
    TCPSend($Server, "Test")
    TCPCloseSocket($Server)
    TCPShutdown()
    Exit
EndIf

$MainSocket = TCPListen(@IPAddress1, $Port)
If $MainSocket = -1 Then
    MsgBox(0 , "Error!", "Could not listen in on port ;_;")
    Exit 1
EndIf

Switch @Compiled
    Case 1
        Run(FileGetShortName(@ScriptFullPath))
    Case 0
        Run(FileGetShortName(@AutoItExe) & ' /AutoIt3ExecuteScript ' & FileGetShortName(@ScriptFullPath))
EndSwitch

$ConnectedSocket = -1

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

While 1
    $Recv = TCPRecv($ConnectedSocket, 2048)
    If $Recv = "Test" Then
        ConsoleWrite("Online" & @CR)
        _Exit()
    EndIf
WEnd

Func _Exit()
    TCPCloseSocket($ConnectedSocket)
    TCPShutdown()
    Exit
EndFunc
Edited by FlutterShy
Posted

I guess port forwarding is the issue for me.

I am wondering is there any way to avoid port forwarding because I don't really want to have to mess with my router if I don't have to.

Posted

I guess port forwarding is the issue for me.

I am wondering is there any way to avoid port forwarding because I don't really want to have to mess with my router if I don't have to.

That's probably not an option :(

Things like that are usually really hard, whereever the server's going to be located, it's going to have to have the port it's going to listen on to forwarded to it unless oyu can find out how things like skype and utorrent do it .

  • Developers
Posted

Your router does NATting which means you are sharing with multiple computers on the inside a single IP address on the outside.

There is no way to initiate a connection from the outside in unless you port-forward or define a single internal IPaddress which will receive all inbound connections (DMZ host).

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Thanks very much for the help and information everyone ^_^

I only plan on having the server run on my computer but it's just I don't really like the idea of having to configure the router/hardware but I guess it is no big deal.

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
×
×
  • Create New...