Sockets work fine
#Constant KEY_ESCAPE 27
#Constant TRUE -1
#Constant FALSE 0
#Constant NULL 0
#Constant VOID 0
ListenerID = CreateSocketListener( "anyip4", 4300 ) // Setup Server Connection
SocketID = ConnectSocket( "127.0.0.1", 4300, 3600 ) // Connect to (Local) 127.0.0.1:4300 with a 5s Timeout
Repeat
Select GetSocketConnected( SocketID )
Case -1:
Print( "Failed to Connect")
EndCase
Case 0:
Print( "Connecting.. Please Wait" )
EndCase
Case 1:
Print( "Connected" )
EndCase
EndSelect
Sync()
Until GetRawKeyPressed( KEY_ESCAPE )
// Clean Up
DeleteSocket( SocketID )
DeleteSocketListener( ListnerID )
End
Remember you HAVE to setup the "Listener" to establish the "Server" Connection prior to attempting to Connect to the Socket.
Also keep in mind that a Socket / Listener ID
MUST be a value between 1 - 4,294,967,295., although I'd always recommend letting AppGameKit assign this number; as some of it's functions actually require you to Create and Destroy ID's in order... so it's a good habit to just let AppGameKit handle assignment, that way it only fails when you run out of available IDs.
Also... 127.0.0.1 is a reserved IP., this means Local Machine.
If you want to access another machine on your Network., typically 168.192.xxx.xxx is used for a Local Network; while discovering what an Internet IP is., well that'll take a bit more work.
For example this Computer is:
127.0.0.1 (Local Machine)
168.192.0.202 (Local Area)
82.14.205.123 (Internet IP)
Although keep in mind., the Internet IP (on IPv4) is not Unique for each Device; it's actually the Router/Modem IP... and so if you have Multiple Devices connecting via such., they will each have a Unique ID... I actually would recommend using the MAC (Media Access Control) Address for IDs., as these are Unique Identifiers for said Device' Network Connection.
Now something I wish that AppGameKit did better was allow you to define a Range of Ports with a Single Connection.
What I mean is... just using a Single Port is going to be a problem when you want more than 1 Devices on the same IP to Connect., as this can potentially prevent connections.
Ideally you'll want an additional Port for each Potential Client in a given Server; as they could all be behind a NAT, and to prevent NAT Conflicts; you'll want them each to use their own Port.
You can do this via storing the ListenerID within an Array., and using a For...Next or Repeat...Until to set them up.
Oh and don't remember to also CLOSE the Connections. AppGameKit does a good job of closing / deleting things on exit., but it's a good habit to get into to clean things up yourself.
Esp. if you later plan to learn things like C/C++ where the language DOES NOT clean up after you.