Jump to content

bogQ
 Share

Recommended Posts

Nice tutorial. You should probably look at using variable declaration in your examples. For example your Global declaration should be Local as the variable isn't used anywhere else but in Local scope.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

server is already set to handle more than 1 connection, you just need to:

get rid of msgbox (use gui commands instead) that pause server

limit if needed numebr of connection that it will handle

change how and when will server disconnect clients

Read server part with explained code for more info.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Thanks for the code and tutorial, helpful codes. let me start by saying i am a beginner, so please don't laugh too at my questions!

1. with your codes, I have to run the server and client codes on every PC connected on my network. is there a possibility that I might run the codes for server just once and on the other PCs, i will just have to run but the codes for clients?

2. I wish to have 3 or more Computers, the first computer is my master, where my server runs, the other computers are my client. I wish to send message in both dirrection via TCP as is the case with your codes how am I going to do it?

3. I have tried to open TCP socket via internet but all my attemps have failed. my internet IPaddress is 192.168.1.1

I will be grateful if you find time and provide me some helps.

Best regards

Hubert

Link to comment
Share on other sites

Guess i need to add litle more info about networks on first post

lets expalind it heare like this

I have 2 computers and i need to do TCP over wireless network.

My first computer (he will be server) need to lissen on my second adapter (my first adapter is lan, my second adapter is wireless card), he (wirelles card) is with IP adress @IPAddress2 or 192.168.0.1 (@IPAddress2 is my wireless adapter IP that i manyaly tuped on adapter)

my second computer that have only client on him is with ip address 192.168.0.2 on his wireless lan card and he is connected over that card to my wireless card so that we can be in network, but his IP is not important cos i only need to know server IP adress 192.168.0.1 so that i can connect on him.

so on server im starting it with

$Listen = TCPListen(@IPAddress2, 1018, 500)

or with $Listen = TCPListen('192.168.0.1', 1018, 500), it is identical cos @IPAddress2 will return (in my case) IP address of my second device 192.168.0.1

and on client script im putting

$Socket = TCPConnect('192.168.0.1', 1018)

so im connection on IP adress of server with client

now let's say that i wanna connect more than one pc but not on my wireless network cos it accept only 2 computers, i wanna do it on lan network adapter (my first lan device), on lan i have 6 PC-s connected on network.

My first comp is with ip adress lets say 10.0.252.30 on my local area connection adapter.

How can i confirm that my ip is 10.0.252.30?! From start meny i sellect run (or in win 7 just tupe cmd and hit enter with no run) tupe in cmd and press enter. after that in cmd i type in ipconfig and press enter.

it will list all of your adapters and their ip (IPv4) addresses.

So im gona start server on my network lan adapter

$Listen = TCPListen('10.0.252.30', 1018, 500)

and every client i connect on him will connect to that ip adress

so on client im dooing this

$Socket = TCPConnect('10.0.252.30', 1018)

So i will connect more than one client and only one comp (my first comp) will serve as my server.

Note that somethimes firewall can cose problems, so if you have problems turn it off to see if it will work.

As for internet communication i can't help a lot, i never tried coz my ports are forwarded. Main thing i know is if your behind router form your ISP and your ports arn't forwarded you need to call your ISP on the phone and to tell him to forward that darn port and don't hang up till he say "ok i forwarded it".

If router is in your controll, don't call ISP, take a look at this videos (they are nice tytorials)

and do it yourself ;)

here you can check if others can see you on that port

http://www.yougetsignal.com/tools/open-ports/

or

http://www.canyouseeme.org/

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Thank you bogQ for this terrific tutorial!

The time you put into this is very much appreciated!

Great work!

Would you be okay with taking this to the next level?

-Adding GUI instead of Msgbox

-Having one script work as both server and client to create an Instant Messaging program

-Adding Contact List of all machines that are connected (listed as IP address or @ComputerName

This would probably be a big project, but written in the style that you have already done would be of great help.

I figure it never hurts to ask and certainly you've given us a great base of understanding to work from.

Thank you again!

Edited by coffeeturtle
Link to comment
Share on other sites

  • 3 weeks later...

Thnx for your helpful topic.

I have a question though. I would like to use TCP to connect (lets say) 2 computers but in different houses. So different IP adresses.

So the connection should go via WAN, not LAN. How can I make my real IP adress, like 77.170.181.98, serve as a server?

Thnx in advance :)

Link to comment
Share on other sites

Guess someone with more experience with internet communication should answer this one but if im wrong they can still correct me or at least confirm if this is correct :P (as i stated before "i can't help a lot, i never tried coz my ports are forwarded")

So "if im not wrong",

one computer is server, his public IP address is 77.170.181.98

one client, we dont need to know his ip adress, but he need to know server public IP address.

Server TCPListen on his addapter IP adress (so that isnt 77.170.181.98, we need adapter address) (port must be forwarded on router)

Client connect to 77.170.181.98 server public IP adress.

So client try to connect to server

*Client send msg to server ip adress

77.170.181.98:8080 -> "are you there?"

*router recive msg for port 8080 and forward it on that port to your listening device 10.0.252.30

->77.170.181.98:8080 -> 10.0.252.30:8080 -> "are you there?"

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

that's basically how it works. i just use TCPListen("0.0.0.0", 8080) and it automatically listens on your default adaptor. no need to even get lan/wan ip on the server.

on the router, forward 8080 to your local server ip.

on the client, connect to the servers WAN.

or use @IPAddress1 instead of 0.0.0.0. either should work fine.

edit: 0.0.0.0 makes it listen on "any available" ip, so it will work with multiple adaptoras, i believe.

Edited by caleb41610
Link to comment
Share on other sites

  • 2 weeks later...

Ok thnx for the info.

It is still not working though.

This is a picture of the port I forwarded (is this right??):

Posted Image

And then this is the server script line:

$Listen = TCPListen('192.168.2.8', 8080, 500)

And this is the client's line:

$Socket = TCPConnect('77.170.181.98', 8080)

This should be good, right?

It is not working though, please tell me if I did something wrong

Link to comment
Share on other sites

as i told my isp did not forwarded my ports so i can test

in theory it should work

i posted 2 links in first post

http://www.yougetsignal.com/tools/open-ports/

or

http://www.canyouseeme.org/

so can they see you on port 8080?

another question is , is your port 8080 free? no other program is using him?

did you try on some other port? is your wirewall off?

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Ok thnx for the info.

It is still not working though.

This is a picture of the port I forwarded (is this right??):

Posted Image

And then this is the server script line:

$Listen = TCPListen('192.168.2.8', 8080, 500)

And this is the client's line:

$Socket = TCPConnect('77.170.181.98', 8080)

This should be good, right?

It is not working though, please tell me if I did something wrong

You must also open the port in your firewall.

Link to comment
Share on other sites

Ok still now working.

I changed to port 8081 (just to be sure the port wasn't used by anything else)

I also opened 8081 on my windows firewall.

I checked with the port website, and it says the port is open (if the server is running):

As you see, the port is open.Posted Image

Now when I run the client, I get the following error:

!--> TCPConnect error number ( 10060 ), look in the help file (on MSDN link) on func TCPConnect to get more info about this error.

BTW: I'm running the client and server on the same pc (thus same ip adress). Could this be causing my trouble?

I've been trying to make this work for ages now, please help me out once more!

Thnx :)

Edited by ludocus
Link to comment
Share on other sites

yes it can, if you ever had experience with wamp server or wow servers for example, you couldn't never connect to the site or gameserver on internet connection ip adress from the computer that is running that server, but you can go to that adress if you go to some proxy with browser site and connecting with it with no problems.

so

WSAETIMEDOUT 10060

Connection timed out.

A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host has failed to respond.

can be cuz of that, and in addition it can be cuz of port problem, or something third.

So please do try to connect with 2 different computers with 2 different internet connection on them. (call some friend and tell him to run your client)

if it dont work try some other random ports eg 3724 8129 28960...

and try to lisssen on ip 0.0.0.0

for some other info to "can it realy work" you can look at this post to see that TCP do work on internet if everything is configyred in the correct way and your isp isnt playing with you.

http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • 2 weeks later...

just a quick note from my side, after i convince my isp to geave me some free ports for next month, i tryed to connect over internet on port 8080 today to test do it work or not

tcp lisen on 0.0.0.0 and after that on @IPAddress1 with port 8080, connected to server public IP and message recived, sended, and recived with no problems

port 80 did have probably cos my wamp did use it when i try it on.

So it do work with no problem if everything is configured correctly.

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • 3 years later...

Excellent. This was exactly what I needed.

I have another script I'm building that's generating text output. I wanted to be able to call a separate script running a TCP server, pass the data over Stdin, and have the Server duplicate out whatever data is was sent to whatever clients are connected at the time, and manage listening, opening, and closing Sockets.

I have something like this compiled to .EXE, though if running as an .au3 file, it will prompt you with an Input box for data to send. Connect and disconnect as many Telnet (Putty, Teraterm) sessions as you want and they start getting output.

 

#include <Array.au3>
#include <WinAPIProc.au3>
;Ref https://www.autoitscript.com/forum/topic/144987-learning-about-tcp-servers-and-clients-connection/
    $ParentPID = _WinAPI_GetParentProcess()
TCPStartup()
OnAutoItExitRegister("OnAutoItExit")
    Dim $Socket_Data[1]
$Socket_Data[0] = 0
$Listen = TCPListen("0.0.0.0", 1018, 500)
If @error Then
    ConsoleWrite('!--> TCPListen error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPListen to get more info about this error.' & @CRLF)
    Exit
EndIf
    While ProcessExists($ParentPID)
    If @Compiled=0 Then
        $TCPdata=InputBox("TCPServer","Type Data to send")
    Else
        $TCPData = ConsoleRead()
        EndIf
        If StringLen($TCPData) > 0 Then
        For $x = $Socket_Data[0] To 1 Step -1
            TCPSend($Socket_Data[$x], $TCPData)
            If @error Then
                _CloseConnection()
            EndIf
        Next
    EndIf
    _Accept()
    Sleep(500)
WEnd
    Func _Accept()
    Local $Accept = TCPAccept($Listen)
    If $Accept <> -1 Then
        _ArrayAdd($Socket_Data, $Accept)
        $Socket_Data[0] += 1
    EndIf
EndFunc   ;==>_Accept
    Func _CloseConnection()
    _ArrayDelete($Socket_Data, $x)
    $Socket_Data[0] -= 1
EndFunc   ;==>_CloseConnection
    Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

    I then use this script to establish the link to Stdin:
     

    #include <AutoItConstants.au3>
$iPID = Run("tcpserver.exe", "", @SW_HIDE, $STDIN_CHILD)
While 1
    $Data=InputBox("Input","data")
    StdinWrite($iPID,$Data)
Wend
   

 

Edited by TurionAltec
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

×
×
  • Create New...