Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCP/IP invalid handle error. What can I do?
#1
Hi friends,
please help me to find where I have coded the bug...

Code: (Select All)

$Unstable:Http

Screen _NewImage(512, 512, 256)

Dim a(511, 511) As Integer 'an array we'll send

x = _OpenClient("TCP/IP:1234:localhost") 'try to connect to a host

If x = 0 Then 'couldn't be client, so become a host
    'put some data into array a
    For xx = 0 To 511
        For yy = 0 To 511
            a(xx, yy) = xx * yy
        Next
    Next
    Print "(Try passing data via TCP/IP!)"
    Print "Waiting... (Press any key to end)"
    x = _OpenHost("TCP/IP:1234")
    If x = 0 Then Print "failure to create host" Else Print "Host ON"
End If


x = _OpenClient("TCP/IP:1234") 'try to connect to a host
Print x
If x < 0 Then
    z = _OpenConnection(x)
    Print "z"; z
    'connect to host as a client



    If z < 0 Then
        Print "Connected to host. Reading data..."
        Do
            Put #z, , a() 'send array a to any client that connects
            Close z
            Print "Array data send to client!"


            Get #x, , a()
            _Limit 100
        Loop Until EOF(x) = 0 'wait until enough data to fill the array arrives
        For xx = 0 To 511
            For yy = 0 To 511
                PSet (xx, yy), a(xx, yy)
            Next
        Next
        Close x
        Print "That's how you share data folks!" 'G@lleon
        Do: Loop Until InKey$ = ""
    Else
        Print "Failure connection with z "; z
    End If
    _Limit 10

    Print "Finished!"
    End

Else
    Print "Failure to create host client connection "; x
End If

End

I get always the message of error "invalid Handle" on line ... (that of _OPENCONNECTION instruction) but I am not able to understand why.
Thanks for time spent for helping me
Reply
#2
Is it so corrrect?

Code: (Select All)

$Unstable:Http

Screen _NewImage(512, 512, 256)

Dim a(511, 511) As Integer 'an array we'll send

x = _OpenClient("TCP/IP:1234:localhost") 'try to connect to a host

If x = 0 Then 'couldn't be client, so become a host
    'put some data into array a
    For xx = 0 To 511
        For yy = 0 To 511
            a(xx, yy) = xx * yy
        Next
    Next
    Print "(Try passing data via TCP/IP!)"
    Print "Waiting... (Press any key to end)"
    x = _OpenHost("TCP/IP:8080")
    If x = 0 Then Print "failure to create host" Else Print "Host ON"
End If


x2 = _OpenClient("TCP/IP:8080:localhost") 'try to connect to a host
Print x2
If x2 < 0 Then
    z = _OpenConnection(x)
    Print "z"; z
    'connect to host as a client



    If z < 0 Then
        Print "Connected to host. Reading data..."
        Do
            Put #z, , a() 'send array a to any client that connects
            Close z
            Print "Array data send to client!"


            Get #x2, , a()
            _Limit 100
        Loop Until EOF(x2) = 0 'wait until enough data to fill the array arrives
        For xx = 0 To 511
            For yy = 0 To 511
                PSet (xx, yy), a(xx, yy)
            Next
        Next
        Close x2
        Print "That's how you share data folks!" 'G@lleon
        Do: Loop Until InKey$ = ""
    Else
        Print "Failure connection with z "; z
    End If
    _Limit 10

    Print "Finished!"
    End

Else
    Print "Failure to create host client connection "; x2
End If

End

I dont know if so is it correct. First send data to port 1234 and next receive data from 8080?


Reply
#3
There's several little things wrong with it here, so we're talking it out over on Discord and tweaking them one at a time.  Hopefully we'll help Tempodi get this sorted before long.   Wink
Reply
#4
Hi friends
thanks to Steve with his help I got solution of the issue...so it is SOLVED!

and this is the code working well
Code: (Select All)

$Unstable:Http

Screen _NewImage(512, 512, 256)

Dim a(511, 511) As Integer 'an array we'll send

x = _OpenClient("TCP/IP:1234:localhost") 'try to connect to a host

If x = 0 Then 'couldn't be client, so become a host
    'put some data into array a
    For xx = 0 To 511
        For yy = 0 To 511
            a(xx, yy) = xx * yy
        Next
    Next
    Print "(Try passing data via TCP/IP!)"
    Print "Waiting... (Press any key to end)"
    x = _OpenHost("TCP/IP:1234")
    If x = 0 Then Print "failure to create host" Else Print "Host ON"
    'End If


    x2 = _OpenClient("TCP/IP:1234:localhost") 'try to connect to a host
    Print x2
    If x2 < 0 Then
        z = _OpenConnection(x)
        Print "z"; z
        'connect to host as a client



        If z < 0 Then
            Print "Connected to host. Reading data..."
            ' Do
            Put #z, , a() 'send array a to any client that connects
            ' Close z
            Print "Array data send to client!"


            Get #z, , a()
            _Limit 100
            '  Loop Until EOF(z) = 0 'wait until enough data to fill the array arrives
            For xx = 0 To 511
                For yy = 0 To 511
                    PSet (xx, yy), a(xx, yy)
                Next
            Next
            Close z
            Print "That's how you share data folks!" 'G@lleon
            Do: Loop Until InKey$ = ""
        Else
            Print "Failure connection with z "; z
        End If
        _Limit 10

        Print "Finished!"
        End

    Else
        Print "Failure to create host client connection "; x
    End If
End If
End
Reply




Users browsing this thread: 1 Guest(s)