Xojo.Net.TCPSocket - How to tell if Send is Complete?

Hey all,

I’m trying to upload an image to a device using a Xojo.Net.TCPSocket. Copying the image to a memory block and writing it works great. However, I have no idea when the transfer is done. There is no “SendComplete” event in the Xojo.Net.TCPSocket (I have no idea why).

How can you know if a file transfer has completed??

Use flush(), or possibly poll()

I did hear that flush() is possibly not reliable so I made my own using poll(), thus:

// Replacement for flush(). Checks error conditions, and uses poll.

if  (me.connstateOK=false)  Then Return False        // Error this request

While  (True)
  
  me.Poll ()                                         // Get latest status from the socket
  
  if  (me.IsConnected=False)  then
   // log an error message
    return false
  end if
  
  if  (me.LastErrorCode>0)  then
   // log an error message
    return false
  end if
  
  If  (me.BytesLeftToSend<=0)  Then return true
  
Wend

In the ios tcpsocket there seems to be no way in native xojo. A declare may be possible but i don’t know what the underlay apple class is.

Tim - The Flush() and Poll() methods do not exist in the Xojo.Net.TCPSocket.

Humph! That would acount for why I never used it. :wink:

Maybe an idea is to wait for a data response? of a specific type?

Yeah. Unfortunately I’m dumping into a NetCat socket on the other end.

Is it pre-setup or can you modify it ?

No. It’s on a device from a third party.

Ah… i can’t think of something quick. We are limited as well. So your only options are tcp?

Newer versions of the device firmware have an HTTP based API which I am looking at using as the Xojo.Net.HTTPSocket has more events where I can detect stuff like this. I am having some trouble but will post that in another thread.

2 Likes