Trying to bind UDP socket to a port from a C++ DLL used in Ruby

I have a DLL in C++, loaded in Ruby and used its API, the DLL is trying to find a free UDP port to bind to. This works just ok in a normal command line app and other apps using that DLL. It doesnt work when under SketchUp!
Tried everything, disabled Antivirus, etc.
Does Sketchup restricts the use of UDP ports or something ?
Btw, connecting to a TCP server works ok, but UDP cant bind to any port.
So, UDP from C++ DLL, not Ruby socket scripting. The DLL is loaded in Ruby.
Tried to bind to a range of port numbers, tried random port, nothing. Any idea?

Becuase you are very vague, this is the only thing I can suggest:

I tried not to be vague :).
I wrote a C++ DLL, in which I am using the SFML library to bind an UDP socket to any available port.
This DLL is used in other executables, where it works perfectly, binds to UDP ports ok.
When the DLL is loaded with Ruby in Sketchup, and its function connect called, it seems it cant find a free port to bind the UDP socket to. The DLL is also using TCP which seems to work fine. What’s even more peculiar, UDP data sending works.
The problem is binding the UDP socket to a port. Doesnt work.

I might try to bind UDP from Ruby networking api just to check if it at least works in scripting.

Ruby is programmed in C, so you can hover over a method in the docs, and a “toggle source” link will appear:

But in embedded Ruby, the application (SketchUp) controls when Ruby runs. So, sometimes we have problems with things getting blocked.

We can sometimes use a timer feature in the API (which is a wrapper for a C++ timer):

# within your module or class
# (perhaps within a method)
@max = 10
@step = 1
@tid = UI.start_timer(interval) {
  if @step == @max
    @tid = nil
  # make a bind call here
  # test result of the bind call
  # if success then stop the timer if it's not nil
  @step += 1

:warning: Do not open a modal window inside a timer block !