System.Net.Sockets.UdpClient.BeginSend C# (CSharp) Méthode

BeginSend() public méthode

public BeginSend ( byte datagram, int bytes, string hostname, int port, AsyncCallback requestCallback, object state ) : IAsyncResult
datagram byte
bytes int
hostname string
port int
requestCallback AsyncCallback
state object
Résultat IAsyncResult
        public IAsyncResult BeginSend(byte[] datagram, int bytes, string hostname, int port, AsyncCallback requestCallback, object state)
        {
            if (_active && ((hostname != null) || (port != 0)))
            {
                // Do not allow sending packets to arbitrary host when connected.
                throw new InvalidOperationException(SR.net_udpconnected);
            }

            IPEndPoint ipEndPoint = null;
            if (hostname != null && port != 0)
            {
                IPAddress[] addresses = Dns.GetHostAddressesAsync(hostname).GetAwaiter().GetResult();

                int i = 0;
                for (; i < addresses.Length && addresses[i].AddressFamily != _family; i++)
                {
                }

                if (addresses.Length == 0 || i == addresses.Length)
                {
                    throw new ArgumentException(SR.net_invalidAddressList, nameof(hostname));
                }

                CheckForBroadcast(addresses[i]);
                ipEndPoint = new IPEndPoint(addresses[i], port);
            }

            return BeginSend(datagram, bytes, ipEndPoint, requestCallback, state);
        }

Same methods

UdpClient::BeginSend ( byte datagram, int bytes, AsyncCallback requestCallback, object state ) : IAsyncResult
UdpClient::BeginSend ( byte datagram, int bytes, IPEndPoint endPoint, AsyncCallback requestCallback, object state ) : IAsyncResult

Usage Example

        public ServerContext(int port, int maxclients, ref List<string> TextStack, string OwnIP)
        {
            BeginSendUdpServerCallback = new AsyncCallback(OnBeginSendUdpServerCallbackFinished);
            ServerMessage = System.Text.Encoding.ASCII.GetBytes("OK:" + OwnIP);

            UdpServer = new UdpClient(new IPEndPoint(IPAddress.Any, 8011)); //da bei xp fehler

            UdpServer.JoinMulticastGroup(BroadcastServer.Address);

            UdpServer.BeginSend(ServerMessage, ServerMessage.Length, BroadcastServer, BeginSendUdpServerCallback, null);

            MaxClients = maxclients;

            Ip = IPAddress.Any;
            this.Port = port;

            listener = new TcpListener(Ip, Port);
            Clients = new List<ClientContext>(MaxClients);

            listener.Start();

            BeginAcceptSocketCallback = new AsyncCallback(OnClientConnected);

            this.TextStack = TextStack;
        }
All Usage Examples Of System.Net.Sockets.UdpClient::BeginSend