Re: [twsocket] HttpCli & ContentRangeBegin
> (1) What happens if I use ContnetRangeBegin and the server doesn't > support ranges (ex: if I'm downloading the results of a script)? Will I > end up with the whole document append to the already downloaded portion > of the document? You'll get an error. > (2) I noticed there's a AcceptRanges property that's set up by THttpCli > from the headers it receives while processing a request. I supose this > is server-dependent. Can I make use of this to determine if ranges are > supported? I think so. > (3) In the code running after a failed download I'm removing the last > portion of the received data, just in case it's corrupted. I noticed > this behavior in a freeware download manager I used to use some time > ago. But now I'm asking: is this really necessary? HTTP traffic travels > over TCP and TCP is supposed to be an checksummed, reliable protocol. Is > the probability of receiving corrupt data high enough to make such > radical surgery useful? If so, is tail-trimming the best solution, or > should I implement some other kind of checksumming to make sure no > portion of the code is actually corrupt (after all, corruption might > occur anywhere in the document, not just in the last received portion). You are right, I don't see any reason to throw away part of the received data. By TCP protocol specification, only valid data is delivered to the application. If you get it, it is correct data. -- Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: "Cosmin Prund" <[EMAIL PROTECTED]> To: "ICS support mailing" Sent: Thursday, November 16, 2006 10:47 AM Subject: [twsocket] HttpCli & ContentRangeBegin > Hello. > > I've build a "download manager" module for my application arround > THttpCli and I'm making use of ContentRangeBegin to resume failed > downloads. It all works very nice and smooth, and all my downloads > resume fine. Unfortunately my downloads only fail when I unplug the > network cable from my computer OR when I disable my network adapter... > and I don't think those are the most common causes of disconnections for > the average user! So I'll have to ask about "abnormal" situations, just > to make sure I'm getting things right: > > (1) What happens if I use ContnetRangeBegin and the server doesn't > support ranges (ex: if I'm downloading the results of a script)? Will I > end up with the whole document append to the already downloaded portion > of the document? > (2) I noticed there's a AcceptRanges property that's set up by THttpCli > from the headers it receives while processing a request. I supose this > is server-dependent. Can I make use of this to determine if ranges are > supported? > (3) In the code running after a failed download I'm removing the last > portion of the received data, just in case it's corrupted. I noticed > this behavior in a freeware download manager I used to use some time > ago. But now I'm asking: is this really necessary? HTTP traffic travels > over TCP and TCP is supposed to be an checksummed, reliable protocol. Is > the probability of receiving corrupt data high enough to make such > radical surgery useful? If so, is tail-trimming the best solution, or > should I implement some other kind of checksumming to make sure no > portion of the code is actually corrupt (after all, corruption might > occur anywhere in the document, not just in the last received portion). > > Thanks, > Cosmin Prund > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Connection catch-22
> When I call TWSocket's Send method, I'm getting error 10057, > "Send Socket is not connected" It is because you call Send immediately after Calling Connect. TWSocket is a NON-BLOCKING component. When you call Connect, you get control back immediately (the next line execute immediately) while the connection is established in the background (It could take several seconds on the Internet). Once the connection is established, you have OnSessionConnected triggered and you can start sending data. When you send data, you data goes into a send buffer and you get control back - again - immediately while you data is sent at network speed in the background. Once your data in sent (the buffer is emptyed), you get OnDataSent event. You may call several Send in a raw, your data is simply appended in the internal send buffer. You get OnDataSent only when the buffer is emptyed, not for each send. So in your code, move your sending code to OnSessionConnected event handler, after of course having tested ErrCode argument to know if the connection was successful. Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] SmtpClient problem on disconnect
Hello all: I'm having problems SmtpCli where OnRequestDone function is not fired after sending QUIT command because the SMTP server is not closing the connection!!. It occurs only when using EHLO command and AUTH LOGIN authentication. I have tryed with 2 servers with same results (big linux servers). To solve that, I have changed SmtpProt.pas: FROM: procedure TCustomSmtpClient.NextExecAsync; ... ... if Assigned(FDoneAsync) then FDoneAsync else if (FRequestType <> smtpQuit) or (FConnected = FALSE) then TriggerRequestDone(FRequestResult) else begin { We have to wait until remote host close connection before } { calling TriggerRequestDone. See WSocketSessionClosed. } end; end; TO: procedure TCustomSmtpClient.NextExecAsync; ... ... if Assigned(FDoneAsync) then FDoneAsync else TriggerRequestDone(FRequestResult) end; end; ...then in the OnRequestDone I can close connection (if necessary) by calling CloseDelayed. any idea?? thanks in advance, David -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Telnet problems
Hello, I've some big problems with the telnet components, the biggest one being the lack of documentation. What I want to do is the following: 1. start a telnet session (that one works) 2. have a list of commands 3. loop through the list and carry out one command after the other 4. display the telnet output in some window, scrollable so that I can see the history to verify it. What I'm doing right now is: 1. start a telnet connection 2. wait until isconnected becomes true or 2 sec. Timeout (the telnetserver is the only node on a local lan so it's fast and works reliably) 3. In the OnDataAvailable I do this: if endofcommands = false then begin TnEmulVT.SendStr(nextcommandstring); end; Where commandstring will be sometings like '2'+#13 or 'mytext'+#13 or ''+#13. 4. the device on the other side is menu based where each menu item has a number unique to that menu level. e.g. the main menu might look like this: 1. first submenu 2. second submenu If I go to 2nd submenu another menu is displayed: 1. do something 2. do something other 3. set testtext If I go to the 2nd submenu and select the 3. item I get a prompt: enter your text: After this prompt I want to enter text and if it is terminated by #13 I get the 2nd submenu displayed again, (seems normal) where I can get up to the main menu by just sending #13. I get to the "set testtext" menu already and the prompt is displayed, but my text sent is not entered as it seems. I've a breakpoint in nDataAvailable but it is only reached twice, so the call of that menu works but the text isn't enered because it's nerver being sent due to OnDataAvailabe not being raised. LocalEcho is off. My program simply displays the terminal then and when I enter some chars they're always shown twice in the terminal. Why is this? I tried OnLocalEcho as well but I think the results where even worse, I think it only occured once and then stopped. What good is OnEndOfRecord for besides? I think I can't use TnScript, because the same menu items will be displayed several times because I have to "traverse" the submenus several times. Scrolling back also messes up the whole TnEmulVT as well as changing the font size and lineheight (the cursor is between the lines then). So this would be a enhancement request ( ;-) ) to properly support these things. Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Shutdown(How: Integer)
When do I need, or would I want, to call Shutdown(), and what are the ramifications of the different parameters that one can pass it. I see Shutdown(2) in one of the demo apps, but don't know what "2" represents. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Need example code for identifying a record before processing
I will be receiving a variety of structs/records, all of different sizes and "makeups". How can I (in the OnDataAvailable() handler, I assume), determine/identify which record has just come in, so that I can process it accordingly? OnDataAvailable() should only fire once for each record, because I am having the sender add a #126 (~) as the last byte of each record, and using LineMode with LineEnd = #126. All of the records have as their first member an Integer named OpCode which identifies itself as to which type of record it is, such as: PInductionComplete = ^TInductionComplete; TInductionComplete = packed record OpCode: Integer; Sort: Integer; CarrierCount: Integer; GreenLightMilliseconds: Integer; OccupiedTrays: Integer; RecordTerminator: Char; //This is the #126, or tilde/~ char end; Can I use PeekData() for this, and then, after looking under the hood, pass the record off intact to the appropriate method? If yes, does anybody have a code sample, or at least pseudocode for this? If no, does anybody have code sample or pseudocode for how I should handle it instead? I want to be able to do something like this: procedure TfClientMain.WSocket_AsServerDataAvailable(Sender: TObject; ErrCode: Word); const BLA = 1; BLEE = 2; Var iOpCode: Integer; begin if ErrCode <> 0 then begin ClientDM.InsertException( CurrentUser, Format(sErrorNInWSocket_AsServerDataAvailable, [ErrCode]), GetHostNameOrDefaultIPAddress); Exit; end; iOpCode := ExtractOpCode from record case iOpCode of BLA: ProcessBla(SocketData) BLEE: ProcessBlee(SocketData) . . . end; The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] SmtpClient problem on disconnect
David A. G. wrote: > Hello all: > > I'm having problems SmtpCli where OnRequestDone function is not fired > after sending QUIT command because the SMTP server is not closing the > connection!!. We've been talking this topic many times. The RFCs say that the server has to close the connection, so if a server doesn't close the connection on receiving command QUIT the server is buggy. You can handle those server-side bugs with a simple command timeout, in real applications some a timeout mechanism is required anyway. Arno Garrels > TO: > > procedure TCustomSmtpClient.NextExecAsync; > ... > ... > if Assigned(FDoneAsync) then > FDoneAsync > else > TriggerRequestDone(FRequestResult) > end; > end; Request done has to be triggered either when the request has been served or an error occured, I thing your change breaks the concept of the component. --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] HttpCli & ContentRangeBegin
Francois PIETTE wrote: >> (3) In the code running after a failed download I'm removing the last >> portion of the received data, just in case it's corrupted. I noticed >> this behavior in a freeware download manager I used to use some time >> ago. But now I'm asking: is this really necessary? HTTP traffic travels >> over TCP and TCP is supposed to be an checksummed, reliable protocol. Is >> the probability of receiving corrupt data high enough to make such >> radical surgery useful? If so, is tail-trimming the best solution, or >> should I implement some other kind of checksumming to make sure no >> portion of the code is actually corrupt (after all, corruption might >> occur anywhere in the document, not just in the last received portion). >> > > You are right, I don't see any reason to throw away part of the received > data. By TCP protocol specification, only valid data is delivered to the > application. If you get it, it is correct data. > I did a bit of googling on TCP, IP and transport layer checksumming and found some interesting results. It seems that TCP provides an additive checksum to protect it's payload, and apparently that's not very strong. Transport layers provide allot stronger passwords: Ethernet uses 32 bit CRC checksums, PPP uses 16 bit CRC checksums and ATM uses a 8 bit CRC checksum that only protects the header. The weakest link from HTTP server to CLIENT is probably the link from CLIENT to ISP. The worst case scenario would be a dial-up connection using PPP-only. A better but still bad scenario would be an ADSL connection running PPP-over-ATM (because ATM does not seem to checksum it's payload). Most of my clients would fit in one of those 2 groups! Considering those facts, throwing away part of the already received data might be a good thing IF the connection to the HTTP server was lost because the client lost it's connection to the ISP. Chances are the connection to the ISP was lost because the line became noisy. If the connection to the HTTP server was lost on grounds of network congestion then throwing away part of the received data would be meaningless since the chances for data corruption are equal all over the received data, they're not higher towards the end of the file. Conclusion: I think data corruption might be a problem in some cases. Notice how all Linux distributions include MD5 hashes for all downloads, so they can be checked on the receiving end? I decided to implement MD5-based file checking for my downloads (my application only downloads stuff from my own site, so I've got everything under my control). I've done this because I know I've got quite a few clients on very bad dial-up lines. If I didn't have those clients I would have done no checking at all. -- Cosmin Prund -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] SmtpClient problem on disconnect
In my opinion, the servers are not compliant with the standard. Indtead of tweaking the component, either simply colse the connection yourself or implement a timeout and close it later if the server don't do it quickly enough for you. Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: "David A. G." <[EMAIL PROTECTED]> To: "TWsocket" Sent: Friday, November 17, 2006 12:05 AM Subject: [twsocket] SmtpClient problem on disconnect > Hello all: > > I'm having problems SmtpCli where OnRequestDone function is not fired after > sending QUIT command because the SMTP server is not closing the > connection!!. It occurs only when using EHLO command and AUTH LOGIN > authentication. I have tryed with 2 servers with same results (big linux > servers). > > To solve that, I have changed SmtpProt.pas: > > FROM: > > procedure TCustomSmtpClient.NextExecAsync; > ... > ... > if Assigned(FDoneAsync) then > FDoneAsync > else if (FRequestType <> smtpQuit) or (FConnected = FALSE) then > TriggerRequestDone(FRequestResult) > else begin > { We have to wait until remote host close connection before } > { calling TriggerRequestDone. See WSocketSessionClosed. } > end; > end; > > > TO: > > procedure TCustomSmtpClient.NextExecAsync; > ... > ... > if Assigned(FDoneAsync) then > FDoneAsync > else > TriggerRequestDone(FRequestResult) > end; > end; > ...then in the OnRequestDone I can close connection (if necessary) by > calling CloseDelayed. > > > any idea?? > > thanks in advance, > David > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Telnet problems
I think TTnScript is the way to go. You can dynamically add/remove events according to which "screen" you detect. If you don't use TTnScript, has a look at his source code to understand how to get hand on the input stream to chack for data. I also uploaded a modified version of the components. It is a proposal of changes by John Porteous. It will probably appear shortly in the distribution. You may try it: http://www.overbyte.be/arch/dump/EmulVTJohnPorteous.zip Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: "Humm, Markus" <[EMAIL PROTECTED]> To: Sent: Friday, November 17, 2006 11:46 AM Subject: [twsocket] Telnet problems > Hello, > > I've some big problems with the telnet components, the biggest one being > the lack of documentation. > > What I want to do is the following: > > 1. start a telnet session (that one works) > > 2. have a list of commands > > 3. loop through the list and carry out one command after the other > > 4. display the telnet output in some window, scrollable so that I can > see the history to verify it. > > What I'm doing right now is: > > 1. start a telnet connection > > 2. wait until isconnected becomes true or 2 sec. Timeout >(the telnetserver is the only node on a local lan so it's fast and > works reliably) > > 3. In the OnDataAvailable I do this: > >if endofcommands = false then >begin > TnEmulVT.SendStr(nextcommandstring); >end; > >Where commandstring will be sometings like '2'+#13 or 'mytext'+#13 or > ''+#13. > > 4. the device on the other side is menu based where each menu item has a > number unique to that menu level. > >e.g. the main menu might look like this: > >1. first submenu >2. second submenu > >If I go to 2nd submenu another menu is displayed: > >1. do something >2. do something other >3. set testtext > >If I go to the 2nd submenu and select the 3. item I get a prompt: > >enter your text: > >After this prompt I want to enter text and if it is terminated by #13 >I get the 2nd submenu displayed again, (seems normal) where I can get > up to the main menu by just sending #13. > >I get to the "set testtext" menu already and the prompt is displayed, > but my text sent is not entered as it seems. >I've a breakpoint in nDataAvailable but it is only reached twice, so > the call of that menu works but the text >isn't enered because it's nerver being sent due to OnDataAvailabe not > being raised. LocalEcho is off. >My program simply displays the terminal then and when I enter some > chars they're always shown twice in the terminal. >Why is this? > >I tried OnLocalEcho as well but I think the results where even worse, > I think it only occured once and then stopped. >What good is OnEndOfRecord for besides? > >I think I can't use TnScript, because the same menu items will be > displayed several times because I have >to "traverse" the submenus several times. > > Scrolling back also messes up the whole TnEmulVT as well as changing the > font size and lineheight > (the cursor is between the lines then). So this would be a enhancement > request ( ;-) ) to properly support these things. > > Greetings > > Markus > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Pulling my hair out trying to receive a record
I am trying to test sending records from a utility to my app, which should receive and process the records. I am able to send the record from my test utility with this code: procedure TForm10.btnSendMsgAsRecordClick(Sender: TObject); begin InitializeWSocketProperties; WSocket_AsClient.Connect; end; procedure TForm10.InitializeWSocketProperties; begin WSocket_AsClient.Addr := '10.172.2.93'; { TODO : After testing, read these vals from an .INI file } WSocket_AsClient.Port := '1234'; end; {== After connecting, this event is called ==} procedure TForm10.WSocket_AsClientSessionConnected(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then begin ShowMessage(Format('Error in OnSessionConnected() event: %d', [ErrCode])); Exit; end; SendTheCurrentRecord; end; procedure TForm10.SendTheCurrentRecord; begin if cmbxMsgType.Items[cmbxMsgType.ItemIndex] = 'ACTIVATE_BOF_SORT' then SendActiv8BOFSortRecord //This is the one I'm testing . . . procedure TForm10.SendActiv8BOFSortRecord; var X: PActivateBOFSort; Ptr: PByte; iSent, iSize, iErrorCode: Integer; begin iSize := SizeOf(TActivateBOFSort); X := AllocMem(iSize); X^.OpCode := ACTIVATE_BOF_SORT; X^.Carrier := StrToIntDef(edt1.Text, 0); StrLCopy(X^.BOFSortLabel, PChar(edt2.Text), BOF_SORT_LABEL_LENGTH); X^.WorkstationOffset := StrToIntDef(edt3.Text, 0); X^.RecordTerminator := '~'; Ptr := PByte(X); while iSize > 0 do begin iSent := WSocket_AsClient.Send(Ptr, iSize); if iSent > 0 then begin Inc(Ptr, iSent); Dec(iSize, iSent); Continue; end; if iSent = 0 then begin ClientSocket.Close; raise Exception.Create('Connection closed gracefully'); end; iErrorCode := WSAGetLastError; if iErrorCode <> WSAEWOULDBLOCK then raise Exception.CreateFmt('Socket Error: %d', [iErrorCode]); end; --and in my "real" app the SessionAvailable() handler is fired, but the SessionConnected() does not, nor does OnDataAvailable(). What am I missing here? What necessary step am I leaving out? I have this code (adapted from one of the ICS demo apps) in the OnSessionAvailable() handler of my receiving app: procedure TfClientMain.WSocket_AsServerSessionAvailable(Sender: TObject; ErrCode: Word); var NewHSocket : TSocket; Peer : String; begin { We need to accept the client connection } NewHSocket := WSocket_AsServer.Accept; { And then associate this connection with our client socket } WSocket_AsClient.Dup(NewHSocket); end; ...and this code in OnSessionConnected(), but it doesn't get reached (also taken from some code gleaned from the mailing list): procedureTfClientMain.WSocket_AsServerSessionConnected(Sender: TObject; ErrCode: Word); begin ICS_RdPtr := 0; ICS_WrPtr := 0; if ICS_BufferSize = 0 then begin ICS_BufferSize := ICS_BUFFER_SIZE; ReAllocMem(ICS_Buffer, ICS_BufferSize); end; end; ...and this preliminary code in OnDataAvailable(), which also is not getting reached: procedure TfClientMain.WSocket_AsServerDataAvailable(Sender: TObject; ErrCode: Word); var sIncomingDataAsString: String; begin if ErrCode <> 0 then begin ClientDM.InsertException( CurrentUser, Format(sErrorNInWSocket_AsServerDataAvailable, [ErrCode]), GetHostNameOrDefaultIPAddress); Exit; end; sIncomingDataAsString := WSocket_AsServer.ReceiveStr; ShowMessage(sIncomingDataAsString); end; Again, what am I missing here? What necessary step am I leaving out or what basic concept do I not understand? I've been struggling with sending data via sockets for several days now. I've given up on the deprecated TClientSocket and TServerSocket components, and am quite frustrated at this point. Does it really have to be this hard to implement? The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] SmtpClient problem on disconnect
> We've been talking this topic many times. > The RFCs say that the server has to close the connection, so if > a server doesn't close the connection on receiving command QUIT > the server is buggy. You can handle those server-side bugs with a simple > command timeout, in real applications some a timeout mechanism is required > anyway. I agree with Arno: breaking the connection after the QUIT command without closing it normally, breaks RFC compliancy and is a bug. Sometimes it is a good idea to modify the components to handle common idiosyncracies of servers that are common, in order to make it more robust. However, in this case, a simple timeout event, as recommended, would correct your problem; and since it is a good idea to implement a command timeout on networking applications anyway, it is not necessary to modify the component to handle this issue. -dZ. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be