本文整理汇总了C#中System.Net.Sockets.Socket.BeginReceiveMessageFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginReceiveMessageFrom方法的具体用法?C# Socket.BeginReceiveMessageFrom怎么用?C# Socket.BeginReceiveMessageFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.Socket
的用法示例。
在下文中一共展示了Socket.BeginReceiveMessageFrom方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SharedSocket
public SharedSocket(int port)
{
addressEntries = new List<AddressEntry>();
this.port = port;
buffer = new byte[65535];
receiveEndpoint = new IPEndPoint(IPAddress.Any, 0);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Bind(new IPEndPoint(IPAddress.Any, port));
socket.BeginReceiveMessageFrom(buffer, 0, buffer.Length, SocketFlags.None, ref receiveEndpoint, OnDataReceived, null);
}
示例2: Arping
public void Arping( IPAddress ipToSearchFor )
{
string ownMAC;
string ownIP;
getLocalMacAndIP( out ownIP, out ownMAC );
char[] aDelimiter = { '.' };
string[] aIPReso = ipToSearchFor.ToString().Split( aDelimiter, 4 );
string[] aIPAddr = ownIP.Split( aDelimiter, 4 );
byte[] oPacket = new byte[] { /*0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
Convert.ToByte("0x" + ownMAC.Substring(0,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(2,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(4,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(6,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(8,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(10,2), 16),
0x08, 0x06,*/ 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x01,
Convert.ToByte("0x" + ownMAC.Substring(0,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(2,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(4,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(6,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(8,2), 16),
Convert.ToByte("0x" + ownMAC.Substring(10,2), 16),
Convert.ToByte(aIPAddr[0], 10),
Convert.ToByte(aIPAddr[1], 10),
Convert.ToByte(aIPAddr[2], 10),
Convert.ToByte(aIPAddr[3], 10),
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Convert.ToByte(aIPReso[0], 10),
Convert.ToByte(aIPReso[1], 10),
Convert.ToByte(aIPReso[2], 10),
Convert.ToByte(aIPReso[3], 10)};
Socket arpSocket;
arpSocket = new Socket( System.Net.Sockets.AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Raw );
//arpSocket.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true );
arpSocket.EnableBroadcast = true;
EndPoint localEndPoint = new IPEndPoint( IPAddress.Any, 0 );
EndPoint remoteEndPoint = new IPEndPoint( ipToSearchFor, 0 );
arpSocket.Bind( localEndPoint );
arpSocket.BeginSendTo( oPacket,0,oPacket.Length,SocketFlags.None, remoteEndPoint, null, this);
byte[] buffer = new byte[100];
arpSocket.BeginReceiveMessageFrom( buffer, 0, 100, SocketFlags.None, ref remoteEndPoint, null, this);
}
示例3: StartListening
public void StartListening()
{
lock (lockobj) {
ResetStats();
hasData = true;
if (socket == null) {
receiveEndpoint = new IPEndPoint(IPAddress.Any, 0);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Bind(new IPEndPoint(IPAddress.Any, this.endpoint.Port));
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(this.endpoint.Address));
socket.BeginReceiveMessageFrom(buf, 0, buf.Length, SocketFlags.None, ref receiveEndpoint, ReceiveCallback, socket);
}
}
}