Jump to content
Sign in to follow this  
SkellySoul

Tcp Problem

Recommended Posts

SkellySoul

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

Share this post


Link to post
Share on other sites
trancexx

You are mixing up several different things. Google port forwarding.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkellySoul

I catch an error at this part of the script.

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

Share this post


Link to post
Share on other sites
Chance

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

Share this post


Link to post
Share on other sites
SkellySoul

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.

Share this post


Link to post
Share on other sites
Chance

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 .

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
SkellySoul

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.

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  

×