public BeginSendTo ( byte buffer, int offset, int size, SocketFlags socketFlags, |
||
buffer | byte | |
offset | int | |
size | int | |
socketFlags | SocketFlags | |
remoteEP | ||
callback | AsyncCallback | |
state | object | |
return | IAsyncResult |
byte[] buffer = Encoding.ASCII.GetBytes("Hello World"); IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("192.168.1.10"), 1234); socket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None, remoteEndpoint, SendCallback, socket);
byte[] buffer = Encoding.ASCII.GetBytes("Broadcast message"); IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, 1234); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); socket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None, endPoint, SendCallback, socket);In this example, we create a byte array with a message to broadcast. We then create an endpoint specifying the broadcast address and port number. We set the SocketOptionName.Broadcast option to 1 to enable broadcasting. We then call the BeginSendTo method to send the message to all hosts on the network. Package library: System.Net.Sockets.
public BeginSendTo ( byte buffer, int offset, int size, SocketFlags socketFlags, |
||
buffer | byte | |
offset | int | |
size | int | |
socketFlags | SocketFlags | |
remoteEP | ||
callback | AsyncCallback | |
state | object | |
return | IAsyncResult |