Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Context.Connection.Socket.WriteInteger() not available?
#1
On the old version of Indy 10, I noticed that WriteInteger wasn't available - a bit of a pain when i was trying to send file sizes before sending files!

On this version (10.6.3.3) there is still no WriteInteger() procedure available yet it was in Indy 9 (and 8 I think too).

How can I get around this please?

Thanks
Reply
#2
(10-23-2024, 08:00 PM)Justin Case Wrote: On the old version of Indy 10, I noticed that WriteInteger wasn't available - a bit of a pain when i was trying to send file sizes before sending files!

On this version (10.6.3.3) there is still no WriteInteger() procedure available yet it was in Indy 9 (and 8 I think too).

How can I get around this please?

In Indy 8 and 9, WriteInteger() and ReadInteger() were methods of TIdTCPConnection.

In Indy 10, all of the reading/writing methods were moved to TIdIOHandler, and the WriteXXX() methods were changed into Write(XXX) overloads. Old versions of Indy 10 had a Write(Integer) overload, while modern Indy 10 has a Write(Int32) overload instead (all versions of Indy 10 also have a Write(Int64) overload).

And FYI, Indy 8, 9 and 10 all have methods to write/read a TStream with a preceding size Integer (Indy 8 and 9) or Int32/Int64 (Indy 10).

Reply
#3
Ok, thanks. Yes I knew about the integer being written preceding the TStream but obviously that's for Indys use from my POV - when I want to send a transfer request to a client I'd like to be able to send the file ahead of the stream being written!

Anyway thank you once again for your help and time that you donate to us indy users!
Reply
#4
(10-24-2024, 08:49 PM)Justin Case Wrote: Ok, thanks. Yes I knew about the integer being written preceding the TStream but obviously that's for Indys use from my POV

It is for the protocol's use. If the protocol requires a preceding size, then Indy has a convenient wrapper to make that easier.

(10-24-2024, 08:49 PM)Justin Case Wrote: when I want to send a transfer request to a client I'd like to be able to send the file ahead of the stream being written!

I assume you meant the stream size, right? IE if you wanted to send the stream size, then get an acknowledgement before then sending the actual stream. That is certainly doable, even in Indy 10.

Reply
#5
Daft Question (forgive me!) what is WriteFile() ? - Is this the gift that we've all been waiting for for many years? - a simple way of sending a file without worrying about streams and all that malarky?

If it is then how come there is no ReadFile() ?

(10-24-2024, 09:19 PM)rlebeau Wrote:
(10-24-2024, 08:49 PM)Justin Case Wrote: when I want to send a transfer request to a client I'd like to be able to send the file ahead of the stream being written!

I assume you meant the stream size, right?  IE if you wanted to send the stream size, then get an acknowledgement before then sending the actual stream.  That is certainly doable, even in Indy 10.

Good job you still have that psychic gift! Yes you are correct, I was meaning the file/stream size.
Reply
#6
(10-24-2024, 09:22 PM)Justin Case Wrote: Daft Question (forgive me!) what is WriteFile() ? - Is this the gift that we've all been waiting for for many years?

WriteFile() has existed for a very long time, going way back to at least Indy 8, if not earlier (before my time).

(10-24-2024, 09:22 PM)Justin Case Wrote: a simple way of sending a file without worrying about streams and all that malarky?

WriteFile() is a wrapper for the Win32 TransmitFile() API on Windows, which takes an open file handle and dumps the file data directly onto a socket. If Indy is running on a Windows NT-based system (which includes anything after W2K/XP), and the AEnableTransferFile parameter is true (among other conditions), then WriteFile() opens the file with CreateFile() and sends it with TransmitFile(). Otherwise, it just uses a TFileStream and sends that instead. Either way, no preceding size is sent.

(10-24-2024, 09:22 PM)Justin Case Wrote: If it is then how come there is no ReadFile() ?

Because there is no corresponding Win32 API to receive a transmitted file from a socket. So you just have to use ReadStream() instead.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)