Sign in to follow this  
Followers 0
tsolrm

TCP

22 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

I have checked the firewall and made sure the port 403 is open.

However when i'm trying to run it (at least on the same PC) its not working. :D

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm running it on the same PC.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

TCPStartup: 0

and

no connection. Error: 10061

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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)



            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
tsolrm   

    
        
    
             0
    
        
    

        
            
                Adventurer
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                145 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #15 · 
            Posted 
            
            
            
        
    

    


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


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
water   

    
        
    
             1,685
    
        
    

        
            
                ?
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             1,685
    
        
    

                22,631 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #16 · 
            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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Anyone? I thought this is simple enough!

Server is on my PC

And the client is someplace else and is sending me a simple message using my IP address. But for some reason there is no connection

Share this post


Link to post
Share on other sites

$TCPConnect = TCPConnect ("my ip", 1111)

sleep (5000)

After I've put sleep there, it returns $TCPConnect as -1 but @error as 0! What does that mean?

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0