Modify

Opened 12 years ago

Closed 6 years ago

#2513 closed Bug (Rejected)

TCPSend() Not functioning with string over 225 characters in length.

Reported by: NullSchritt Owned by:
Milestone: Component: AutoIt
Version: 3.3.9.21 Severity: None
Keywords: Cc:

Description

Hello I have found a bug that appears to be present in all the most recent beta releases of autoit, if TCPSend() is used with a string greater than 225 characters in length, all data is lost.

TCPSend Error Example:

 TCPStartup()
$ip = InputBox("Destination", "Destination IP")
$sock = TCPConnect($ip, 7337)
;~ TCPSend($sock, "DATA TEST 1")
$DT1 = ""
for $i=1 to 225
	$DT1 &= Random(1,9,1)
Next
TCPSend($sock, $DT1) ; this will be received properly
$DT2 = ""
for $i=1 to 226
	$DT2 &= Random(1,9,1)
Next
TCPSend($sock, $DT2) ; this will be received as a blank string
MsgBox(64, "Done", "Sent both packets")

Receive Script(modified from help file):

#include <GUIConstantsEx.au3>

; If you select the server button, start this script before and select the client button on:
; the second instance of this script OR on the example script TCPSend and vice versa.

Example()

Func Example()
    TCPStartup() ; Start the TCP service.

    ; Register OnAutoItExit to be called when the script is closed.
    OnAutoItExitRegister("OnAutoItExit")

    ; Assign Local variables the loopback IP Address and the Port.
    Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer.
    Local $iPort = 7337 ; Port used for the connection.

    #region GUI
    Local $hGUI = GUICreate("TCPRecv", 150, 70)

    Local $iBtnServer = GUICtrlCreateButton("1. Server", 10, 10, 130, 22)

    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $iBtnServer
                _TCPRecv_Server($sIPAddress, $iPort)
        EndSwitch

        Sleep(10)
    WEnd
    #endregion GUI
EndFunc   ;==>Example

Func _TCPRecv_Server($sIPAddress, $iPort)
	ConsoleWrite("Listening..."&@CRLF)
    ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions.
    Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
    Local $iError = 0

    ; If an error occurred display the error code and return False.
    If @error Then
        ; Someone is probably already listening on this IP Address and Port (script already running?).
        $iError = @error
        MsgBox(64, "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError)
        Return False
    EndIf

    ; Assign a Local variable to be used by the Client socket.
    Local $iSocket = 0

    Do ; Wait for someone to connect (Unlimited).
        ; Accept incomming connexions if present (Socket to close when finished; one socket per client).
        $iSocket = TCPAccept($iListenSocket)
    Until $iSocket <> -1 ;if different from -1 a client is connected.

    ; Assign a Local variable the data received.
    Local $sReceived = TCPRecv($iSocket, 2048) ;we're waiting for the string "toto" OR "tata" (example script TCPSend): 4 bytes length.

    ; Display the string received.
    ConsoleWrite("Server:" & @CRLF & "Received: " & $sReceived&@CRLF)

    ; Close the socket.
    TCPCloseSocket($iSocket)
	TCPCloseSocket($iListenSocket)
EndFunc   ;==>_TCPRecv_Server



Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

Attachments (2)

server.au3 (3.0 KB ) - added by FireFox 12 years ago.
client.au3 (2.8 KB ) - added by FireFox 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by J-Paul Mesnage, 12 years ago

In fact the "problem" does not come from 225 to 226 but from the fact that such script is not design to handle several TCPSend()

I am not familiar with TCP usage so I cannot help more.

comment:2 by NullSchritt, 12 years ago

This error does not always seem to be present, but occurs what seems rather randomly.

comment:3 by J-Paul Mesnage, 12 years ago

For me 226 is not the problem.
Almost sure your script does not handle more than one post

by FireFox, 12 years ago

Attachment: server.au3 added

by FireFox, 12 years ago

Attachment: client.au3 added

comment:4 by FireFox, 12 years ago

Please ignore the files I attached.

I created another ticket #2670 not to hijack this one.

comment:5 by J-Paul Mesnage, 6 years ago

Resolution: Rejected
Status: newclosed

no more info so I close it

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.