Jump to content

TCP


tsolrm
 Share

Recommended Posts

Hi guys

I want to make a server that's running constantly and receiving messages from different clients.

So far i've managed to do it with a simple message from a local client. How can i make it receive messages from any IP, not just local ones?

==server==

TCPStartup()
$TCPListen = TCPListen (@IPAddress1, 403)

Do 
$TCPAccept = TCPAccept($TCPListen)
Until $TCPAccept <> -1

Do
$TCPRec = TCPRecv ($TCPAccept, 1000000)
Until $TCPRec <> -1

MsgBox (0, "test", $TCPRec)

==client==

TCPStartup ()
$TCPConnect = TCPConnect (@IPAddress1, 403)
If $TCPConnect = -1 then 
MsgBox (0, "no", "no connection")
Exit
EndIf
TCPSend($TCPConnect, "HELLO")
Edited by tsolrm
Link to comment
Share on other sites

I don't see you script limit the IP-addresses it accepts pakets from. Might be your firewall doesn't allow incoming connections.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

If you move the client to another computer, do you change the ip-adress in the klient script?

$TCPConnect = TCPConnect (@IPAddress1, 403)

It needs to be changed to the ip-adress of the computer where the server is running.

If you do, then check firewall as water said.

Challenge accepted!

Link to comment
Share on other sites

What's missing in your scripts is error checking! Every AutoIt function returns a value or sets @error to show that an error occurred. So please check @error after each TCP function call and post what you get.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

It's given me an error 10061

I've googled it WSAECONNREFUSED 10061

Connection refused.

No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.

Edited by tsolrm
Link to comment
Share on other sites

Do you have any kind of "protection" software installed on the client or server PC? Like virus scanner, HIPS etc. It might not only be the firewall that refuses the connection. Did you check the firewall on both PC's?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

But from your first post I got the impression that the code there was working fine on a single PC.

I tested your client/server code and it worked fine.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

no but i tried it like this

==client==

$myip = "here's my IP"

TCPStartup ()

$TCPConnect = TCPConnect ($myip, 403)

If $TCPConnect = -1 then

MsgBox (0, "no", "no connection")

Exit

EndIf

TCPSend($TCPConnect, "HELLO")

and it doesn't connect :D

Link to comment
Share on other sites

Could you please restart your PC to make sure that no server/client code is haning around?

What do you get if you run the following version with more error checking?

$myip = "here's my IP"
TCPStartup ()
msgBox(16, "Info", "TCPStartup: " & @error)
$TCPConnect = TCPConnect ($myip, 403)
If @error <> 0 then
  MsgBox (0, "no", "no connection. Error: " & @error)
  Exit
EndIf
TCPSend($TCPConnect, "HELLO")
MsgBox (16, "Info", "TCPSend: " & @error)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Just to make sure. The server part (as posted at the beginning) is successfully running?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Yes this code is running

==server==

TCPStartup()
$TCPListen = TCPListen (@IPAddress1, 403)

Do
$TCPAccept = TCPAccept($TCPListen)
Until $TCPAccept <> -1

Do
$TCPRec = TCPRecv ($TCPAccept, 1000000)
Until $TCPRec <> -1

MsgBox (0, "test", $TCPRec)



            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


tsolrm
            
            
                Posted 
                
            
        
    
    
        


tsolrm
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 145
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            I don't know, i've tried switching off the firewall completely and the antivirus too!


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


water
            
            
                Posted 
                
            
        
    
    
        


water
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                MVPs
                
                    
                
            
            
                
                    
                        
                            
                                
                            
                                 26.6k
                            
                                
                            
                        
                        
                            
                                
                                    
                                        
                                        188
                                
                                    
                                
                            
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            I modified the scripts a bit so they now write to a log file:
Server:
#include <file.au3>
$iResult = TCPStartup()
_FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPStartup return value: " & $iResult & ", @error: " & @error)
$TCPListen = TCPListen(@IPAddress1, 403)
_FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPListen return value: " & $TCPListen & ", @error: " & @error)
Do
    $TCPAccept = TCPAccept($TCPListen)
Until $TCPAccept <> -1

Do
    $TCPRec = TCPRecv($TCPAccept, 1000000)
    _FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPRecv return value: " & $TCPRec & ", @error: " & @error)
Until $TCPRec <> -1

MsgBox(0, "test", $TCPRec)

Client:

#include <file.au3>
$iResult = TCPStartup()
_FileWriteLog("C:\temp\TCP.log", "TCP Client - TCPStartup return value: " & $iResult & ", @error: " & @error & @LF)
$TCPConnect = TCPConnect(@IPAddress1, 403)
_FileWriteLog("C:\temp\TCP.log", "TCP Client - TCPConnect return value: " & $TCPConnect & ", @error: " & @error)
If $TCPConnect = -1 Then
    MsgBox(0, "no", "no connection")
    Exit
EndIf
$iResult = TCPSend($TCPConnect, "HELLO")
_FileWriteLog("C:\temp\TCP.log", "TCP Client - TCPSend return value: " & $iResult & ", @error: " & @error)

Compile the scripts, start server.exe and then client.exe and post the log file c:\temp\tcp.log

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

2011-12-09 17:09:31 : TCP Server - TCPStartup return value: True, @error: 0

2011-12-09 17:09:31 : TCP Server - TCPListen return value: 608, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPStartup return value: True, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPConnect return value: 608, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPSend return value: 5, @error: 0

Link to comment
Share on other sites

2011-12-09 17:09:31 : TCP Server - TCPStartup return value: True, @error: 0

2011-12-09 17:09:31 : TCP Server - TCPListen return value: 608, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPStartup return value: True, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPConnect return value: 608, @error: 0

2011-12-09 17:09:34 : TCP Client - TCPSend return value: 5, @error: 0

The logfile shows that everything worked fine on the client side. Returnvalue 5 for TCPSend means: 5 bytes sent.

On the server side there seems to be a problem with TCPAccept (because the TCPRecv message never shows up). Could you please change the server code and repeat the test:

#include <file.au3>
$iResult = TCPStartup()
_FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPStartup return value: " & $iResult & ", @error: " & @error)
$TCPListen = TCPListen(@IPAddress1, 403)
_FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPListen return value: " & $TCPListen & ", @error: " & @error)
Do
    $TCPAccept = TCPAccept($TCPListen)
    _FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPAccept return value: " & $TCPAccept & ", @error: " & @error)
Until $TCPAccept <> -1

Do
    $TCPRec = TCPRecv($TCPAccept, 1000000)
    _FileWriteLog("C:\temp\TCP.log", "TCP Server - TCPRecv return value: " & $TCPRec & ", @error: " & @error)
Until $TCPRec <> -1

MsgBox(0, "test", $TCPRec)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

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