Jump to content
Sign in to follow this  
Innovative

Cant send binary ?

Recommended Posts

This is the client and the server of my script.. This was suppose to send files thru tcp network , but no matter what , the fileWrite function just dont write to the exe or zip file the binary data even if i use FileOpen($path, 17)

client

#Include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)
GuiCreate("Transfer accelerator - Receiver", 350, 190)
$path_Label = GuiCtrlCreateLabel("File full path to save :", 15, 13, 350)
GuiCtrlSetFont($path_Label, 8, 400, -1, "Terminal")
$path_Input = GuiCtrlCreateInput("", 15, 35, 150, 20)
$browse_button = GuiCtrlCreateButton("...", 170, 35, 25, 20)
$path_Label = GuiCtrlCreateLabel("Internet Protocol (IP Address) Target :", 15, 62, 350)
GuiCtrlSetFont($path_Label, 8, 400, -1, "Terminal")
$ip_Input = GuiCtrlCreateInput("", 15, 80, 150, 20)
GuiCtrlSetData($ip_Input, @ipaddress1)
GuiCtrlSetState($ip_Input, $GUI_DISABLE)
$path_Label = GuiCtrlCreateLabel("Transfer speed :", 15, 113, 350)
GuiCtrlSetFont($path_Label, 8, 400, -1, "Terminal")
GUICtrlCreateSlider (10, 130, 150)

$send_Button = GuiCtrlCreateButton("Receive", 220, 128, 70, 30)
$status_Label = GuiCtrlCreateLabel("Status : Ready to Receive !", 15, 165, 330)
GuiSetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $browse_button
            $browse = FileSaveDialog ("Choose path to save (WITHOUT BACKSLASH)..", @desktopdir, "All (*.*)", 2+16)
            GuiCtrlSetData($path_Input, $browse)
        Case $msg = $Send_button
            GuiCtrlSetData($status_label, "Status : Declaring receive variables ...")
            $s_path = GuiCtrlRead($path_Input)
            $s_IP = GuiCtrlRead($ip_Input)
            Sleep(1000)
            GuiCtrlSetData($status_label, "Status : Waiting for sender to connect to network ...")
            TCPStartup()
            $MainSocket = TCPListen(@ipaddress1, 3389)
            If $MainSocket = -1 Then MsgBox(48, "Network error", "A network establishing process has encountered an error and will stop the progress!")
$ConnectedSocket = -1
                Do
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
Do
    $recv = TCPRecv($ConnectedSocket, 9999)
Until StringLen($Recv)
GuiCtrlSetData($status_label, "Status : "& $recv &" has connected to your network! ...")
$recv = ""
Sleep(2000)
GuiCtrlSetData($status_label, "Status : Waiting for binary data from remote networks ...")
Do
    $recv = TCPRecv($ConnectedSocket, 9999)
Until StringLen($recv)

$f_type = _StringBetween($recv, "<type>", "</type>")

$recv = StringReplace($recv, "<type>"& $f_type[0] &"</type>", "")
GuiCtrlSetData($status_label, "Status : Writing binary data to selected file path ...")

            $s_Binarydata = _BinaryWriteFile($s_path)
            
            Sleep(1000)
GuiCtrlSetData($status_label, "Status : Checking file status ...")

            If $s_BinaryData = 0 Then
                GuiCtrlSetData($status_label, "Status : File not received ! Probably port 3389 was blocked.")
            Else
                GuiCtrlSetData($status_label, "Status : File sucessfully received !")
                Endif
        EndSelect
Wend
Func _BinaryWriteFile($f_Path)
    _FileCreate($f_Path & $f_type[0])
    $f_Open = FileOpen($f_Path & $f_type[0], 17)
    FileWrite($f_Open, $recv)
    $f2_Open = FileOpen($f_Path & $f_Type[0], 16)
    $f_read = FileRead($f2_Open)
    If $f_read = "" Then
        Return 0
        SetError(1)
    Else
        Return 1
        Endif
    EndfuncoÝ÷ ÚÇ«½êÚºÚ"µÍÒ[ÛYH   ÑÕRPÛÛÝ[Ë]LÉÝÂÜ
    ][ÝÕ^P]]Ô]ÙI][ÝË
BÜ
    ][ÝÕ^SY[S[ÙI][ÝËJBÝÝZPÜX]J  ][ÝÕ[ÙXØÙ[]ÜHÙ[][ÝËÍLNL
BÌÍÜ]ÓX[HÝZPÝÜX]SX[
    ][ÝÑ[H[]
ËÛÈZ[[ÈXÚÜÛÚ
H][ÝËMKLËÍL
BÝZPÝÙ]Û
    ÌÍÜ]ÓX[
LK  ][ÝÕZ[[   ][ÝÊBÌÍÜ]Ò[]HÝZPÝÜX]R[]
    ][ÝÉ][ÝËMKÍKML
BÌÍØÝÜÙWØ]ÛHÝZPÝÜX]P]Û  ][ÝË][ÝËMÌÍKK
BÌÍÜ]ÓX[HÝZPÝÜX]SX[
    ][ÝÒ[]ÝØÛÛ
TYÜÊHÙ]][ÝËMK
ÍL
BÝZPÝÙ]Û
    ÌÍÜ]ÓX[
LK  ][ÝÕZ[[   ][ÝÊBÌÍÚÒ[]HÝZPÝÜX]R[]
    ][ÝÉ][ÝËMKML
BÌÍÜ]ÓX[HÝZPÝÜX]SX[
    ][ÝÑ[HH][ÝËMKLLËÍL
BÝZPÝÙ]Û
    ÌÍÜ]ÓX[
LK  ][ÝÕZ[[   ][ÝÊBÌÍØÛÛX×ÛX[HÝZPÝÜX]PÛÛXÊ ][ÝËVI][ÝËMKLÌML
BÝZPÝÙ]]J    ÌÍØÛÛX×ÛX[   ][ÝËßTQßÒQTßÓP_TTTÒ_STSÕTÕÓ][ÝË    ][ÝËVI][ÝÊBÌÍÜÙ[Ð]ÛHÝZPÝÜX]P]Û    ][ÝÔÙ[   ][ÝËL
ÌÌ
BÌÍÜÝ]×ÓX[HÝZPÝÜX]SX[
    ][ÝÔÝ]ÈXYHÈÙ[ ÌÌÎÉ][ÝËMKMKÌÌ
BÝZTÙ]Ý]J
BÚ[HB  ÌÍÛÙÈHÕRQÙ]ÙÊ
BÙ[XÝØÙH    ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑB^]BPØÙH    ÌÍÛÙÈH ÌÍØÝÜÙWØ]ÛBBIÌÍØÝÜÙHH[SÜ[X[ÙÈ
    ][ÝÐÚÛÜÙHÙ[[]][ÝËÚÝÜ    ][ÝÐ[

I][ÝËJÌÎ
BBBQÝZPÝÙ]]J ÌÍÜ]Ò[] ÌÍØÝÜÙJBØÙH ÌÍÛÙÈH ÌÍÔÙ[Ø]ÛBBBÝZPÝÙ]]J    ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈXÛ[ÈÙ[XXÈ][ÝÊBBBIÌÍÜ×Ü]HÝZPÝXY
    ÌÍÜ]Ò[]
BBBIÌÍÜ×ÒTHÝZPÝXY
    ÌÍÚÒ[]
BBBIÌÍÜ×ÕHHÝZPÝXY
    ÌÍØÛÛX×ÛX[
BBBTÛY
L
BBBRY   ÌÍÜ×ÒTH    ][ÝÉ][ÝÈ[BBBSÙÐÞ
M   ][ÝÐXØÙÜÈ[YY  ÌÌÎÉ][ÝË  ][ÝÔXÙH[][[]ÝØÛÛYÜÈ
TYÜÊHÙ]ÈÛÛ[YIÌÌÎÉ][ÝÊBBBBQÝZPÝÙ]]J   ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈXYHÈÙ[ ÌÌÎÈ][ÝÊBBH[ÙRY  ÌÍÜ×Ü]H    ][ÝÉ][ÝÈ[BBBSÙÐÞ
M   ][ÝÐXØÙÜÈ[YY  ÌÌÎÉ][ÝË  ][ÝÔXÙH[]H[IÌÎNÜÈ[]ÈÛÛ[YIÌÌÎÉ][ÝÊBBBBQÝZPÝÙ]]J   ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈXYHÈÙ[ ÌÌÎÈ][ÝÊBBBQ[ÙRY ÌÍÜ×ÕHH    ][ÝÉ][ÝÈ[BBBSÙÐÞ
M   ][ÝÐXØÙÜÈ[YY  ÌÌÎÉ][ÝË  ][ÝÔXÙHÙ[XÝH[HHÈÛÛ[YIÌÌÎÉ][ÝÊBBBBQÝZPÝÙ]]J ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈXYHÈÙ[ ÌÌÎÈ][ÝÊBBBBQ[ÙBBBQÝZPÝÙ]]J   ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈÛÛXÝ[ÈÈÙ][]ÝØÛÛ
TYÜÊH][ÝÊBBBUÔÝ

BBBIÌÍÐÛÛXÝYÛØÚÙ]HÔÛÛXÝ
    ÌÍÜ×ÒTÌÎJBBBUÔÙ[
    ÌÍÐÛÛXÝYÛØÚÙ]YÜÌJBBBTÛY
Ì
BBBQÝZPÝÙ]]J ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈXY[È[H[JÊH]H][ÝÊBBBIÌÍÜ×Ð[Y]HHÐ[TXY[J  ÌÍÜ×Ü]
BBBTÛY
L
BBBQÝZPÝÙ]]J ÌÍÜÝ]×ÛX[ ][ÝÔÝ]ÈÙ[[È[JÊH][ÝÊBBBIÌÍÜ×ÔÙ[HÔÙ[
    ÌÍÐÛÛXÝYÛØÚÙ] ][ÝÉÝIÝÉ][ÝÈ [È ÌÍÜ×ÕH [È ][ÝÉËÝIÝÉ][ÝÈ   [È ÌÍÜ×Ð[Q]JBBBRY ÌÍÐÛÛXÝYÛØÚÙ]HLHS ÌÍÜ×ÔÙ[H[BBBQÝZPÝÙ]]J  ÌÍÜÝ]×ÛX[ ][ÝÔÝ]È[HÝÙ[  ÌÌÎÈØXHÜÌÎHØÈØÚÙY][ÝÊBBBQ[ÙBBBBQÝZPÝÙ]]J ÌÍÜÝ]×ÛX[ ][ÝÔÝ]È[HÝXÙÜÙ[HÙ[ ÌÌÎÉ][ÝÊBBBBQ[YBBBQ[Y[Ù[XÝÙ[[ÈÐ[TXY[J    ÌÍÙÜ]
BÌÍÜ×ÓÜ[H[SÜ[    ÌÍÙÜ]MBÌÍÜ×ÔXYH[TXY
    ÌÍÜ×ÓÜ[BY ÌÍÜ×ÔXYH   ][ÝÉ][ÝÈ[T]LBTÙ]ÜJB[ÙBT] ÌÍÜ×ÜXYQ[YQ[[

Share this post


Link to post
Share on other sites

Maybe because you are trying to read and write the same file at the same time?

Func _BinaryWriteFile($f_Path)
    _FileCreate($f_Path & $f_type[0])
    $f_Open = FileOpen($f_Path & $f_type[0], 17)        ;Opened here...
    FileWrite($f_Open, $recv)                   ;Wrote here
    FileClose($f_Open)                          ;**********Try adding this?********
    $f2_Open = FileOpen($f_Path & $f_Type[0], 16)       ;Opened again here?
    $f_read = FileRead($f2_Open)
    FileClose($f2_Open)                         ;*** And add this maybe? ***
    If $f_read = "" Then
        Return 0
        SetError(1)
    Else
        Return 1
    Endif
Endfunc

Share this post


Link to post
Share on other sites

Same problem , before sending it should be like some confusing words but after FileWrite, the content of the received file is in binary which should not be in because i used

$opened = FileOpen($path, 17) ; Open for binary WRITE or READ

FileWrite($opened, $data)

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  

×
×
  • Create New...