Dart.PowerTCP.SslSockets Namespace > Udp Class > Open Method : Open() Method |
Allocate a socket at an ephemeral port for sending and receiving datagrams.
[Visual Basic]
<DescriptionAttribute("Open a default system IP address/port")>
Overloads Public Sub Open()
[C#]
[DescriptionAttribute("Open a default system IP address/port")]
public void Open();
[C++]
[DescriptionAttribute("Open a default system IP address/port")]
public: void Open();
[C++/CLI]
[DescriptionAttribute("Open a default system IP address/port")]
public:
void Open();
This method allocates a socket at the default system address and an ephemeral port for sending and receiving datagrams. Upon successful completion of this method, the local address and port are accessible through the LocalEndPoint property. When using the default system address, the Udp.LocalEndPoint.Address property is "0.0.0.0".
This method must be called in order to successfully use Send, Receive, or JoinMulticastGroup.
The following example demonstrates sending some datagrams to an echo server and receiving the datagrams from the echo server.
[Visual Basic]
Dim iterations as Integer = 3
' Listen on the default interface and an ephemeral port.
udp1.Open()
' Send several datagrams
Dim s as String = "test"
Dim i as Integer
For i=0 to iterations
Udp1.send(s, "MyEchoServer", 7)
Next
' receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
For i=0 to iterations
Dim d as Datagram = Udp1.Receive(s.Length)
Debug.WriteLine(d.ToString())
Next
'* Output
'* ------------------------
'* test
'* test
'* test
'* ------------------------
'*
[C#]
int iterations = 3;
// Listen on the default interface and an ephemeral port.
udp1.Open();
// Send several datagrams
string s = "test";
for(int i=0; i<iterations; i++)
udp1.send(s, "MyEchoServer", 7);
// receive the echoed datagrams, there should be 3...requiring 3 Udp.Receive calls.
for(int i=0; i<iterations; i++)
{
Datagram d = udp1.Receive(s.Length);
Debug.WriteLine(d.ToString());
}
/* Output
* ------------------------
* test
* test
* test
* ------------------------
*/
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Udp Class | Udp Members | Overload List
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.