Jump to content
Sign in to follow this  
JohnOne

Remote TCP connections

Recommended Posts

JohnOne

I'm failing miserably trying to create a TCP client server over internet.

Firewalls disabled on both machines, Client PC can ping Server PC, and visa-versa. also both client and server allowed programs in their respective firewalls anyway.

Error is from TCPConnect() in client.

Server PC has direct connection to Router-less modem (no port forwarding)

Server

TCPStartup()
;Global $IP = _GetIP()
Global $IP = @IPAddress1
;Global $IP = "0.0.0.0"
ConsoleWrite($IP & @LF)
Global $Socket_Data[1]
$Socket_Data[0] = 0
$Listen = TCPListen($IP, 45962, 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 1
    For $x = $Socket_Data[0] To 1 Step -1
        $Recv = TCPRecv($Socket_Data[$x], 1000000)
        If $Recv Then
            MsgBox(0, 'Client Number ' & $x & ' with connected socket identifier ' & $Socket_Data[$x], 'Recived msg from Client: ' & @CRLF & $Recv, 5)
            TCPSend($Socket_Data[$x], 'bye')
            TCPCloseSocket($Socket_Data[$x])
            _ArrayDelete($Socket_Data, $x)
            $Socket_Data[0] -= 1
        EndIf
    Next
    _Accept()
WEnd
Func _Accept()
    Local $Accept = TCPAccept($Listen)
    If $Accept <> -1 Then
        ConsoleWrite("New Connection" & @LF)
        _ArrayAdd($Socket_Data, $Accept)
        $Socket_Data[0] += 1
    EndIf
EndFunc   ;==>_Accept

Client

#include <Inet.au3>
;ConsoleWrite(_GetIP() & @LF)
TCPStartup()
$Socket = TCPConnect("x.x.x.x", 45962); Remote public IP
If @error Then
    MsgBox(0,0,'!--> TCPConnect error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPConnect to get more info about this error.')
    ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPConnect to get more info about this error.' & @CRLF)
    ConsoleWrite('!--> ' & $Socket & @LF)
    Exit
EndIf
TCPSend($Socket, 'Hi there. My computer name is' & ", " & @ComputerName & ", and its drive serial is " & DriveGetSerial(@HomeDrive))
Do
    $Recv = TCPRecv($Socket, 1000000)
Until $Recv
MsgBox(0, 'Recived from server:', $Recv)

Ran both from script and compiled script with and without admin.

Error...

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

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.

Any Ideas folks? I've read a lot of posts with this problem but no posted solutions.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Jos

Have you checked if the server is really listening on port 45962 with "netstat -a" ?
What happens when you run them both on the Server?

Jos

  • Like 1

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
JohnOne

Netstat shows that local adapter address is listening on correct TCP port, foreign address shows as 0.

If I have both client and server on same client machine it works fine.

I will test them both on Server machine asap.

Thanks for advice.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
JohnOne

Works fine on server PC too.

If I switch client and server machines it also works fine.

So when the server is connected via a mobile android device it does not work, but if the client is the android device it's fine.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  

×