Article View: borland.public.cppbuilder.internet.socket
Article #484Re: Indy10 usage
From: Mike Ruskai
Date: Tue, 04 Mar 2008 21:30
Date: Tue, 04 Mar 2008 21:30
51 lines
3135 bytes
3135 bytes
On or about Tue, 4 Mar 2008 09:41:29 -0800 did "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> dribble thusly: > >"Mike Ruskai" <BUTthannydI@DONTearthlinkLIKE.netSPAM> wrote in message >news:ghsqs35tipni65rjlntjpl7hgi6f1bv1g8@4ax.com... > >> Indy supposedly supports SOCKS, so I'm trying to figure out >> how to convert the normal socket code to the bizarre usage of Indy. > >Simply attach a TIdSocksInfo to your TIdTCPClient. It will handle the SOCKS >for you. You don't have to change anything else in your reading/writing >code. You misunderstood. I'm using normal socket code (e.g. connect(), select(), send(), recv(), etc.), not Indy. I'm adding conditional code that uses Indy instead when a SOCKS server is configured. >> One problem is that there's no simple functional equivalent of recv() >> for the IOHandler. > >Yes, there is, which you have already discovered - Readable() and >ReadBytes(). It's not equivalent at all. recv() reads data up to the buffer length specified. ReadBytes() blocks forever until the specified data length is read, or the socket is closed. In other words, ReadBytes() is useless for a normal program (i.e. one without a dedicated socket reading thread) that doesn't know exactly how many bytes are going to be sent over the socket. >> However, while Readable() returns true, both ReadBytes() and >> ReadLn() read nothing at all. > >Please show your actual code. I got that bit sort of working, by adding a delay to Readable(). It's still iffy to use. There is simply no way I can see to loop while receiving available data until the received data is deemed complete (due to the high-level protocol definition). A hack with ReadTimeout and ReadBytes() sort of works, but is so sensitive to network timing that it's worthless. As it happens, the current design uses text-only data on the control connection, so ReadLn() might work for command responses. The data connection exists only for the duration of the transfer, so ReadBytes() may actually work out. Overall, however, I have to say that Indy is a huge pain to work with for someone used to normal socket programming.
Technical Details
Message-ID:
<tefrs3lpnfkk0arr2qa3vospikaj3j491h@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<ghsqs35tipni65rjlntjpl7hgi6f1bv1g8@4ax.com> <47cd89bb$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,ea086d952e8cb041 X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Mike Ruskai <BUTthannydI@DONTearthlinkLIKE.netSPAM> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Indy10 usage Date: Tue, 04 Mar 2008 16:30:59 -0500 Message-ID: <tefrs3lpnfkk0arr2qa3vospikaj3j491h@4ax.com> References: <ghsqs35tipni65rjlntjpl7hgi6f1bv1g8@4ax.com> <47cd89bb$1@newsgroups.borland.com> X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.41.244.203 X-Trace: newsgroups.borland.com 1204666257 65.41.244.203 (4 Mar 2008 13:30:57 -0700) Lines: 51 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail