-1

I need to repetitively send 4 bytes, 00 00 00 F6, every two seconds.
BUT, IdUDPClient.SendBuffer does not return after transmission.

I try sending a few more bytes, and it returns every time.

This works:

UDP.SendBuffer(RawToBytes(#0 + #0 + #0 + #1 + #127 + #128 + #246, 7));

This does not work:

UDP.SendBuffer(RawToBytes(#0 + #0 + #0 + #246, 4));

I have unsuccessfully tried many of the suggestions I have found in various related StackExchange questions.

I have seen at least three scenarios:

  1. Hanging, Wireshark sees 1 transmission.
  2. Working repetitive transmissions, but NOT with 4 bytes of data.
  3. Sometimes bytes > 7F are sent as 3F.

Can someone point out what I am doing wrong?

Edit: The above happens in a thread. If the TIdUDPClient is put as a visible component on a form, then it works fine.

Could this be a threading/reentrancy issue???

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
AndersJ
  • 411
  • 1
  • 3
  • 15
  • Please provide a [Minimal, Complete, and Verifiable example](/help/mvce) that demonstrates the problem. Also, you are misusing `RawToBytes()`. Use `Send()` instead of `SendBuffer()`. Or use `IdGlobal.ToBytes()`. Or construct a `TIdBytes` variable manually. – Remy Lebeau Feb 12 '17 at 00:29
  • @Remy Lebeau I made a MCV to show you, and it worked. Thanks for pushing me to clean up. Must have been a threading issue. Back to the drawing board. – AndersJ Feb 12 '17 at 07:59
  • @Remy Lebeau SetLength of the TidBytes variable is easy to forget :-( – AndersJ Feb 12 '17 at 09:03

1 Answers1

0

It would definitely help to see more of your code, have you made sure that your thread is actually running (calling Execute) otherwise your code won´t run, obviously :)

The difference when using the TIdUDPClient component on a visible form is that it is autocreated (The constructor is run automatically by the delphi designer)

    TIdUDPClient.Create(AOwner: **)

by doing so the component will be operating on the main thread ("GUI thread" if you like)

A few things I´d suggest you do in order to hunt this down is:

First Make sure that the thread is actually executing

The problem could also be that the TIdUDPClient does not have an owner if instantiated with TIdUDPClient.Create(nil) inside the thread, try to instantiate int with and owner either the TThread or the Application

    TIdUDPClient.Create(Self)

or

    TIdUDPClient.Create(Application)

Hope this helps, but as I said posting more of your code would definitely make it possible for me to help you!

Patrik Forsberg
  • 622
  • 9
  • 8