最終更新:2019-12-09 (月) 18:12:16 (1562d)
UdpClient.Send
Top / UdpClient.Send
https://docs.microsoft.com/ja-jp/dotnet/api/system.net.sockets.udpclient.send?view=netframework-4.8
内部
- Client.SendTo? (Socket.SendTo)
- sendto
オーバーロード
Send(Byte[], Int32)
- public int Send (byte[] dgram, int bytes);
- Send メソッド の引数に接続先を指定しない場合、事前に UdpClient.Connect メソッド を呼ぶ必要があります
public int Send(byte[] dgram, int bytes) { // // parameter validation // if (m_CleanedUp){ throw new ObjectDisposedException(this.GetType().FullName); } if (dgram==null){ throw new ArgumentNullException("dgram"); } if (!m_Active) { // // only allowed on connected socket // throw new InvalidOperationException(SR.GetString(SR.net_notconnected)); } return Client.Send(dgram, 0, bytes, SocketFlags.None); }
- Socket.Send
Send(Byte[], Int32, String, Int32)
- public int Send (byte[] dgram, int bytes, string hostname, int port);
public int Send(byte[] dgram, int bytes, string hostname, int port) { // // parameter validation // if (m_CleanedUp){ throw new ObjectDisposedException(this.GetType().FullName); } if (dgram==null){ throw new ArgumentNullException("dgram"); } if (m_Active && ((hostname != null) || (port != 0))) { // // Do not allow sending packets to arbitrary host when connected // throw new InvalidOperationException(SR.GetString(SR.net_udpconnected)); } if (hostname==null || port==0) { return Client.Send(dgram, 0, bytes, SocketFlags.None); } IPAddress[] addresses = Dns.GetHostAddresses(hostname); int i=0; for (;i<addresses.Length && addresses[i].AddressFamily != m_Family; i++); if (addresses.Length == 0 || i == addresses.Length) { throw new ArgumentException(SR.GetString(SR.net_invalidAddressList), "hostname"); } CheckForBroadcast(addresses[i]); IPEndPoint ipEndPoint = new IPEndPoint(addresses[i], port); return Client.SendTo(dgram, 0, bytes, SocketFlags.None, ipEndPoint); }
- Socket.SendTo