khui Posted August 16, 2009 Share Posted August 16, 2009 (edited) Hi, im currently developing a chatclient for me and some of my friends, and ive made a function that will send a file, it all works except one thing. If i try sending a picture on 200kb, it sends a little at a time right, so i used this code snippet: Func recv() Dim $f = -1, $2write $Recv = TCPRecv($SocketData[$0],99999999) $Recv1 = TCPRecv($SocketData[$nr],99999999) For $0 = 1 To $maxcon If StringInStr($Recv,"cmd:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-ALERT-]") EndIf If StringInStr($Recv,"IP:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-ALERT-]") EndIf Next If $Recv1 <> "" Then If $f = -1 Then MsgBox(1,"",$f) $f = FileOpen("C:\Temp\recv\IMG.jpg",2) FileWrite($f,$Recv1) EndIf EndIf If $f <> -1 then FileClose($f) EndFunc But since i use .jpg",2) on the FileOpen it just replaces the last packet so i get like 1/10 of the image file, the first packets shows me 1/10 of the picture or something like that, the second package just gives me a "Corrupt image file". When i do -jpg",1) then it wont delete the old file and therefore i get an error. Also when doing the For $0 = 1 To $maxcon If StringInStr($Recv,"cmd:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-ALERT-]") EndIf If StringInStr($Recv,"IP:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-ALERT-]") EndIf Next i get nothing. Answer ASAP please. Edited August 16, 2009 by khui i > * Link to comment Share on other sites More sharing options...
martin Posted August 16, 2009 Share Posted August 16, 2009 Hi, im currently developing a chatclient for me and some of my friends, and ive made a function that will send a file, it all works except one thing. If i try sending a picture on 200kb, it sends a little at a time right, so i used this code snippet: Func recv() Dim $f = -1, $2write $Recv = TCPRecv($SocketData[$0],99999999) $Recv1 = TCPRecv($SocketData[$nr],99999999) For $0 = 1 To $maxcon If StringInStr($Recv,"cmd:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-alert-]") EndIf If StringInStr($Recv,"IP:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-alert-]") EndIf Next If $Recv1 <> "" Then If $f = -1 Then MsgBox(1,"",$f) $f = FileOpen("C:\Temp\recv\IMG.jpg",2) FileWrite($f,$Recv1) EndIf EndIf If $f <> -1 then FileClose($f) EndFunc But since i use .jpg",2) on the FileOpen it just replaces the last packet so i get like 1/10 of the image file, the first packets shows me 1/10 of the picture or something like that, the second package just gives me a "Corrupt image file". Also when doing the For $0 = 1 To $maxcon If StringInStr($Recv,"cmd:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-alert-]") EndIf If StringInStr($Recv,"IP:") Then ToolTip("Nr." & $0 & " : " & $Recv,0,0,"[-alert-]") EndIf Next i get nothing. Answer ASAP please. People answer as soon as they feel they want to if at all. Asking people to answer ASAP is just daft IMO. Please do no start a new thread to ask the same questions again, you should have waited for replies to your previous thread. I have already pointed out why you are overwriting the data. Every time you open the file with a flag 2 you remove what was there before, if you send the data in 200k byte packets then does that mean you call the recv function for every packet? If so then you must open the file only once at the start of receiving data and only close it when all the data has been received. How do you know that the data you recieve as part of the picture does not contain "cmd:" by bad luck? If your send function is like the one in the other thread then it is faulty as it takes no account of how many bytes were sent, but I assume it is now different. If your send function is now different then we cannot know if that is causing a problem without seeing it. We don't know what some of the varaibles are in your script; for example what is $nr in the recv function? Have a look at some of the many examples and maybe you can use one of them. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
khui Posted August 16, 2009 Author Share Posted August 16, 2009 People answer as soon as they feel they want to if at all. Asking people to answer ASAP is just daft IMO.Please do no start a new thread to ask the same questions again, you should have waited for replies to your previous thread.I have already pointed out why you are overwriting the data. Every time you open the file with a flag 2 you remove what was there before, if you send the data in 200k byte packets then does that mean you call the recv function for every packet? If so then you must open the file only once at the start of receiving data and only close it when all the data has been received.How do you know that the data you recieve as part of the picture does not contain "cmd:" by bad luck?If your send function is like the one in the other thread then it is faulty as it takes no account of how many bytes were sent, but I assume it is now different.If your send function is now different then we cannot know if that is causing a problem without seeing it.We don't know what some of the varaibles are in your script; for example what is $nr in the recv function?Have a look at some of the many examples and maybe you can use one of them.Yet here was one more question and yet what you pointed out doesnt work... So i thought id make a new thread since i also had another question, seems reasonable. i > * 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