dburner Posted December 11, 2007 Share Posted December 11, 2007 Helo, how can i send an JPEG(or any other file types) using TCP protocol. I want to send an image from a client to a server. Link to comment Share on other sites More sharing options...
jps1x2 Posted December 11, 2007 Share Posted December 11, 2007 Why don't you use ftp protocol dburner? If you have opened a socket and you are sending and receiving strings on it from client to server, and you want to send binary data, create a simple protocol, for example like this: CLIENT: Send string "<SNDIMAGE:12345>" where 12345 is the size of the file you want to send SERVER: When the server receives the string "<SNDIMAGE:" it captures the file size that will receive in binary data format. CLIENT: Open file for reading and send binary data of the image file SERVER: Stop parsing client strings received. Open file for writing, receive binary information from client and write that information to the file openend, controlling number of bytes received from the client. SERVER: when number of bytes received from the client are the total indicated in the expresion <SNDIMAGE:XXXXX>, write pending bytes to the file opened fro writing, close that file and continue parsing client strings. You can implement a simple protocol like this: <STR:XXX>text <SNDIMAGE:XXXXXX>binarydata where XXX and XXXXXX is the size of the data sended. See you! Link to comment Share on other sites More sharing options...
dburner Posted December 11, 2007 Author Share Posted December 11, 2007 Well im trying to find the fastest solution to get the image to the server thats why im not using ftp controls. One more question. Do you know any way to reduce the image size?(reduceing the image quality, or by resizing) Link to comment Share on other sites More sharing options...
jps1x2 Posted December 12, 2007 Share Posted December 12, 2007 I don't know how to reduce image quality or resize using autoit, but i think that there are utilities to do it. I use batch options of InfanView (http://www.irfanview.com/) for doing that things. You can call that batch functions from autoit and convert/resize/resample an image. It's fast and you have very much options. Link to comment Share on other sites More sharing options...
BAM5 Posted December 12, 2007 Share Posted December 12, 2007 I don't know how to reduce image quality or resize using autoit, but i think that there are utilities to do it.I use batch options of InfanView (http://www.irfanview.com/) for doing that things. You can call that batch functions from autoit and convert/resize/resample an image. It's fast and you have very much options.Try GDIPlus functions. Not sure if any functions are in there to do that. [center]JSON Encoding UDF[/center] Link to comment Share on other sites More sharing options...
BrettF Posted December 12, 2007 Share Posted December 12, 2007 Look at ImageMagik for image quality... Open the file, send it in 250KB chucks, with a 6KB header or something... Might be some image functions in the latest release too... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Kip Posted December 12, 2007 Share Posted December 12, 2007 Why don't you use ftp protocol dburner?well, to use FTP you also have to use TCP.TCP is a Transport LayerFTP is a Application Layer2 different things MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
dburner Posted December 12, 2007 Author Share Posted December 12, 2007 (edited) It looks like i cant get this done . Can somone explain me what am i doing wrong? File Send function Func FileSend($sFile, $IP, $PORT = 4324, $iWaitWhileConnected = 1) Local $conection = -1, $sBuff, $iFileOp,$sRecv TCPStartup() If $iWaitWhileConnected = 1 Then While $conection = -1 $conection = TCPConnect($IP, $PORT) WEnd Else $conection = TCPConnect($IP, $PORT) If @error Then Return SetError(2, 0, -1) EndIf ;TrayTip("connected", "now sending file", 5) $iFileOp = FileOpen($sFile, 16) $sBuff =FileRead($iFileOp) FileClose($iFileOp) TCPSend($conection, "FILESIZE:" & BinaryLen($sBuff)) Sleep(20) While BinaryLen($sBuff) $iSendReturn = TCPSend($iMainSocket, $sBuff) $sBuff = BinaryMid ($sBuff, $iSendReturn + 1, BinaryLen ($sBuff) - $iSendReturn) WEnd Sleep(20) TCPSend($conection, "DONE") Sleep(20) $filename=StringSplit($sFile, "\") $filen=$filename[$filename[0]] TCPSend($conection, "FILENAME:" & $filen) ;TrayTip("file Sent", "your file was sent" , 5) TCPCloseSocket($conection) TCPShutdown() EndFunc File Receive function expandcollapse popupFunc ReceiveFile($IP = @IPAddress1, $PORT = 4324) Local $conection=-1 Local $buffer="" Local $recv="" TCPStartup() $MainSocket = TCPListen($IP, $PORT) Do $conection = TCPAccept($MainSocket); Waiting for connection Until $conection <> -1 While $recv = "" $recv=TCPRecv($conection, 1024) WEnd ;Recive file size in formtat FILESIZE: If StringLeft($recv, 9)="FILESIZE:" Then $fSize=StringTrimLeft($recv, 9) EndIf TrayTip("Receving", "Now Receving file", 5) $buffer=Binary($buffer) TrayTip("Client connected", "Receving file", 5) While $fSize<>BinaryLen($buffer) $recv=TCPRecv($conection, 2048, 1) ;If BinaryToString($recv)="DONE" Then ExitLoop $buffer=$buffer & $recv WEnd TrayTip("" ,"File send. Writing...", 5) While $recv = "" $recv=TCPRecv($conection, 1024) WEnd ;Recive file name in formtat FILENAME: $filename=@YDAY & "-" & @MON & "-" & @YEAR & "-" & @HOUR & ":" & @MIN & ".jpg" If StringLeft($recv, 9)="FILENAME:" Then $filename=StringTrimLeft($recv, 9) If FileExists(@ScriptDir & "\Imagini Primite\" & $filename) Then $k=0 $tmp=$filename While FileExists(@ScriptDir & "\Imagini Primite\" & $tmp) $k=$k+1 $tmp=$filename & "(" & $k & ")" WEnd $filename=$tmp EndIf TrayTip("Saving", "Saving file", 5) $fHandle=FileOpen(@ScriptDir & "\Imagini Primite\" & $filename, 16+2) FileWrite($fHandle, $buffer) FileClose($fHandle) TCPCloseSocket($conection) TCPShutdown() EndFunc Edited December 12, 2007 by dburner Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now