当前位置: 首页>>代码示例>>C#>>正文


C# Socket.BeginReceiveMessageFrom方法代码示例

本文整理汇总了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);
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:14,代码来源:SharedSocket.cs

示例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);
        }
开发者ID:LudovicT,项目名称:Grid-Mapper,代码行数:44,代码来源:SendArping.cs

示例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);
                }
            }
        }
开发者ID:anand-ajmera,项目名称:cornell-urban-challenge,代码行数:18,代码来源:ChannelListener.cs


注:本文中的System.Net.Sockets.Socket.BeginReceiveMessageFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。