Jump to content

UDPOpen and maintaining multiple open UDP ports


Recommended Posts

Hello all!

I have a seemingly undocumented and unsearchable question.  Lets say, I use this line frequenlty to send strings to multiple IP hosts and different times

UDPSend((UDPOpen("192.168.10.1", 6789)), "EXAMPLE")

Now, lets say that I used this command multiple times to the same IP address.  What happens to the last "UDPOpen" commands that I used.  Do they remain open still?  Should I be assigning these ports to variables so that I can close each port that I open immediately after I use it?  I ask because I do not want to lock ports up or create a "memory leak" of sorts by creating multiple ports that never get closed.  I appreciate any help or advice.

Thanks!

Link to comment
Share on other sites

Always open and close network connections.

When you try this:

TCPStartup()

Global $aUDP

$aUDP = UDPOpen("192.168.10.1", 6789)
ConsoleWrite("Socket: " & $aUDP[1] & @CRLF)
$aUDP = UDPOpen("192.168.10.1", 6789)
ConsoleWrite("Socket: " & $aUDP[1] & @CRLF)

UDPCloseSocket($aUDP) ; only last socket closed


TCPShutdown()
you will see that every time a new socket is created!

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...