Login  
Search All Forums
Dart Home | PowerTCP Winsock for ActiveX | Custom Development Reply | PowerTCP Winsock for ActiveX Topics | Forums   
AuthorForum: PowerTCP Winsock for ActiveX
Topic: Error Receiving Large Binary Arrays
emblair3

From: London, United Kingdom
Posts: 12
Member Since: 11/07/02
posted October 20, 2003 8:54 AM

I am trying to send/receive byte arrays of variable length between a client and server written in Excel/VBA. Everything works perfectly so long as I keep the array length under 1455 bytes. However, if I go over this limit, the end of the message (bytes>1455) get lost somewhere. I'm using tcp.Receive and have experimented unsuccessfully with .Search and .Fill. I've also tinkered with increasing .Timeout and .ReceiveBufferSize without any success. Any thoughts?

BTW, my control is a couple years old, but I can't figure out the exact version number. If you can tell me how, I'll dig it up.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted October 20, 2003 9:23 AM

The latest version can always be obtained by downloading and installing the latest trial, then downloading and installing the latest update.exe

Probably what is happening is that the server is sending what you expect in two buffers. If you know the exact size of what you expect, use Fill. I have tried it with the code below to connect and send to an echo server and it worked fine:

  Tcp1.Connect "atropos", 7
  Dim Buffer(2047) As Byte
  Tcp1.Send Buffer
  Tcp1.Fill Buffer
  Tcp1.Close

You could also do the same thing by using Receive:

  Tcp1.Connect "atropos", 7
  Dim Buffer(2047) As Byte
  Tcp1.Send Buffer
  Dim s1 As String
  Dim s2 As String
  Do While Len(s2) < 2049
    s1 = ""
    Tcp1.Receive s1
    s2 = s2 + s1
  Loop
  Tcp1.Close


If you know the exact characters that terminate what you expect, use Search.

emblair3

From: London, United Kingdom
Posts: 12
Member Since: 11/07/02
posted October 20, 2003 10:59 AM

Both the server and the client were written by myself in Excel/VBA using PowerTCP as the WinSock control. Unless there is an undocumented feature in PowerTCP, messages should be sent in their entirety without any second buffer calls.

When I do encounter this >1455bytes problem, I do occasionally receive a second message almost immediately after the first, but this message is always blank, so I don't know where the data has gone to. 

The messages do end with a unique byte sequence, but I encountered strange .Timeout problems when I tried using .Search. 

Each message is of unknown length, but the first four bytes always describe the length of the rest of the message. I've tried using this information by splitting the _Receive into two separate .Fill statements, one for the first 4 bytes and a second for the remaining bytes, but this also encountered timeout problems.

I have definitely upgraded to the latest release with still no joy. I will keep tinkering with the various options, but unless I can fix these problems I am going to have to search for a different package. Thanks all the same for your help.
emblair3

From: London, United Kingdom
Posts: 12
Member Since: 11/07/02
posted October 20, 2003 11:34 AM

I think I might have gotten around my problems. I increased the .SendBufferSize and the .ReceiveBufferSize by x100. Their default is 8,192bytes, I'm now running on 819,200bytes. So long as this doesn't upset anything else, I should be back in action.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted October 20, 2003 11:38 AM

What you state is not true. TCP is a stream oriented protocol.

When you call Send, we submit the data to Winsock and Winsock sends it out in as many buffers of whatever size it feels like.

The same goes for Receiving. If a server is sending you 3000 bytes, it may send 1000, then 2000 or it may send 30 100 byte buffers.

There is no guarantee that the server will send everything you expect in one buffer.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted October 20, 2003 11:42 AM

In regards to your second post:

The buffer size properties you mention set the maximum buffer size, not the actual one that Winsock uses. If it's working by increasing the values, it may or may not work forever. You may encounter a system that refuses to send buffers in the size you request.


emblair3

From: London, United Kingdom
Posts: 12
Member Since: 11/07/02
posted October 21, 2003 4:47 AM

You were right, the buffer solution was only temporary. However, I finally found a robust, working solution. I'm using .Fill to receive the first four bytes, calculate the length of the rest of the message, and then attempt to download the rest using another .Fill. The trick is that I have to set .Timeout=0 and exit the _Receive sub if I don't get what I want immediately. It's a little more complicated than I had initially hoped, but it seems robust. Thanks again for your time.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted October 21, 2003 8:47 AM

Why don't you just exit the Receive event if timeout > 0?

Fill was designed for exactly what you are describing (receiving known quantitys of data)

Reply | PowerTCP Winsock for ActiveX Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX