Jump to content

Need Little help with TCP


Recommended Posts

I Try to send myself a screenshot but the resulting file is NULL, Can some1 plz look and tell me what im doing wrong ?

I Run this to listen to incoming:

$IPADDRESS = @IPAddress2
 $PORT = 33891
 
 TCPStartUp()
 $Socket = TCPListen($IPADDRESS, $PORT)
 If $Socket = -1 Then MsgBox(4112,"Error","$Socket = -1  " & @error)
 $Connected = -1
 MsgBox(0,"","W8ing for connection on Socket: " & $Socket)
 Do
     $Connected = TCPAccept($Socket)
 Until $Connected <> -1
 $Data = TCPRecv($Socket,1000000,1)
 $File = FileOpen(@ScriptDir & "\" & "1.jpg",17)
 FileWrite($File,$Data)
 FileClose($File)
 TCPCloseSocket($Socket)
 TCPShutDown()

And then i run this to send the file :

Opt("TrayIconDebug",1)
 #include <A3LScreenCap.au3>
 _ScreenCap_Capture(@ScriptDir & "\" & "0.jpg")
 TCPStartUp()
 $IPADDRESS = @IPAddress2
 $PORT = 33891
 $Data = ""
 $Socket = TCPConnect($IPADDRESS,$PORT)
 If @error Then
     MsgBox(4112,"Error","TCPConnect failed, error: " & @error)
 Else
     MsgBox(0,"","Sending File on Socket: " & $Socket)
     $File = FileOpen(@ScriptDir & "\" & "0.jpg", 16)
     $Data = FileRead($File)
     TCPSend($Socket,$Data)
     FileClose($File)
 EndIf
 TCPShutdown()

But the resulting new file 1.jpg is 0 bytes, why is that ?

Edited by DaProgrammer
Link to comment
Share on other sites

  • Moderators

FileWrite + 17 is to open it as read only binary isn't it? I would have thought it to be FileWrite + 18

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

FileWrite + 17 is to open it as read only binary isn't it? I would have thought it to be FileWrite + 18

Mode (read or write) to open the file in.
Can be a combination of the  following:
   0 = Read mode
   1 = Write mode (append to end of  file)
   2 = Write mode (erase previous contents)
   4 = Read raw  mode
   8 = Create directory structure if it doesn't exist (See  Remarks).
   16 = Force binary(byte) reading and writing mode with FileRead  and FileWrite
   32 = Use Unicode UTF16 Little Endian mode when writing text  with FileWrite and FileWriteLine (default is ANSI)
   64 = Use Unicode UTF16  Big Endian mode when writing text with FileWrite and FileWriteLine (default is  ANSI)
   128 = Use Unicode UTF8 when writing text with FileWrite and  FileWriteLine (default is ANSI)
Both write modes will create the file if it  does not already exist. The folder path must already exist (except using mode  '8' - See Remarks).

so

16 = Force binary(byte) reading and writing mode with FileRead and FileWrite

+

1 = Write mode (append to end of file)

= 17

that aint the problem :)

Link to comment
Share on other sites

There has been topics on this on the forums, im sure with a bit effort you are able to find em.

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

There has been topics on this on the forums, im sure with a bit effort you are able to find em.

i did like 20 diffrent seaarches and found larrys topic on binary file sending but the _API functions are incomplete in the attached file there so i cant use it unless some1 gives me the Function, so dont tell me i didnt make an effort couse im looking for like 2 hours now ! :)

Link to comment
Share on other sites

And btw, loading the data like you have done might not be the right option.

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Split file into your desired chunks, inn this example each cunk is 1 char.

TCPSend($Socket,"Prepare for file")

$file = FileOpen("your file here",0)
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    TCPSend($Socket,$chars)
Wend

TCPSend($Socket,"Close file")
Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Iwe tested to script above example several times and it wont work, script made by Larry on the other hand works like a charm.

Found here: http://www.autoitscript.com/forum/index.ph...tcp++send++file

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

When I get home I will send you the file send beta for ITS. Probably Monday.

Basically you must API open and read the exact information, and send using the exact packet buffer and size, and from there you must extract that information and paste it into the file. No image file has ever been 100k or even 1000k characters, image files are huge amounts of data so a constant steam of data until receiving an !End command would be more suited for this type of TCP data, and it would be more versitile as well.

-Smith

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...