Sign in to follow this  
Followers 0
svennie

TCPRecv

6 posts in this topic

Like when i send a message "hello" to a server using TCPSend it have to wait until something was sent and then go further receiving and sending.

I already tried this:

While 1
    If TCPRecv($f_Connect,1024) <> "" Then ExitLoop
WEnd

And this:

Do
Until TCPRecv($f_Connect,1024) <> ""

And some other ways.

It's sure it responses.

Since when i use Sleep(1000) it just receive it.

Example of what i am doing:

- Send "hello"

- Wait until response received and ignore it (not immediatly return, because then a message will be send when it's still responsing on my message before)

- Send "hello again"

- Wait until response received ... etc (same as above)

- Send "code"

- Wait until response, receive it fully and then he cacluates what to do with it etc.

So wait until response is the problem B) .


Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites



did you read the TCPSend and TCPRecv examples which implement the Client and Server? B)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Reciever

Dim $Port = 8000
TCPStartup
$MainSocket = TCPListen(@IPAddress1, $Port)
While 1
    $Recv = TCPRecv($ConnectedSocket)
    If $Recv = "" Then
        ExitLoop
    EndIf
    If $ConnectedSocket = -1 Then
        $ConnectedSocket = TCPAccept(MainSocket)
    EndIf
WEnd
MsgBox(0, "Recieved Message!", "You received: " & $Recv)
; Rest of Code
TCPCloseSocket($ConnectedSocket)
TCPCloseSocket($MainSocket)
TCPShutdown()

Sender

Dim $IP = @IpAddress1, $Port = 8000
TCPStartup
$ConnectedSocket = TCPConnect($IpAddress, $Port)
TCPSend($ConnectedSocket, "Hello World!")
TCPCloseSocket($ConnectedSocket)
TCPShutdown()
Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

Reciever

Dim $Port = 8000
TCPStartup
$MainSocket = TCPListen(@IPAddress1, $Port)
While 1
    $Recv = TCPRecv($ConnectedSocket)
    If $Recv = "" Then
        ExitLoop
    EndIf
    If $ConnectedSocket = -1 Then
        $ConnectedSocket = TCPAccept(MainSocket)
    EndIf
WEnd
MsgBox(0, "Recieved Message!", "You received: " & $Recv)
; Rest of Code
TCPCloseSocket($ConnectedSocket)
TCPCloseSocket($MainSocket)
TCPShutdown()

Sender

Dim $IP = @IpAddress1, $Port = 8000
TCPStartup
$ConnectedSocket = TCPConnect($IpAddress, $Port)
TCPSend($ConnectedSocket, "Hello World!")
TCPCloseSocket($ConnectedSocket)
TCPShutdown()
No, that is not what i mean.

It just must pause the script until something is received from te server.


Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Reciever

Dim $Port = 8000
TCPStartup
$MainSocket = TCPListen(@IPAddress1, $Port)
While 1
    $Recv = TCPRecv($ConnectedSocket)
    If $Recv = "" Then
     ; Something Was Received
    EndIf
    If $ConnectedSocket = -1 Then
        $ConnectedSocket = TCPAccept(MainSocket)
    EndIf
WEnd
TCPCloseSocket($ConnectedSocket)
TCPCloseSocket($MainSocket)
TCPShutdown()

Sender

Dim $IP = @IpAddress1, $Port = 8000
TCPStartup
$ConnectedSocket = TCPConnect($IpAddress, $Port)
TCPSend($ConnectedSocket, "Hello World!")
TCPCloseSocket($ConnectedSocket)
TCPShutdown()

The Receiver script WILL NOT do anything unless something is recieved in the first place.

Edited by AutoIt Smith

Share this post


Link to post
Share on other sites

Dim $Port = 8000
TCPStartup
$MainSocket = TCPListen(@IPAddress1, $Port)
$ConnectedSocket = -1 
While $ConnectedSocket = -1
    $ConnectedSocket = TCPAccept(MainSocket)
WEnd
While 1
    $Recv = TCPRecv($ConnectedSocket)
    If $Recv <> "" Then ExitLoop
WEnd
TCPCloseSocket($ConnectedSocket)
TCPCloseSocket($MainSocket)
TCPShutdown()
Thanks it works!

B)


Sorry for my English, I'm Dutch... =DMedia UDFINet Adv UDF

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