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


C# EndPoint.Serialize方法代码示例

本文整理汇总了C#中EndPoint.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# EndPoint.Serialize方法的具体用法?C# EndPoint.Serialize怎么用?C# EndPoint.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EndPoint的用法示例。


在下文中一共展示了EndPoint.Serialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

        public static Internals.SocketAddress Serialize(EndPoint endpoint)
        {
            Debug.Assert(!(endpoint is DnsEndPoint));

            var ipEndPoint = endpoint as IPEndPoint;
            if (ipEndPoint != null)
            {
                return new Internals.SocketAddress(ipEndPoint.Address, ipEndPoint.Port);
            }

            System.Net.SocketAddress address = endpoint.Serialize();
            return GetInternalSocketAddress(address);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:IPEndPointExtensions.cs

示例2: GetIPInfo

		private void GetIPInfo(EndPoint ep, out uint addr, out int port) {
			if (ep.AddressFamily != AddressFamily.InterNetwork) {
				throw new ArgumentException("EndPoint", "Can only handle IPv4 addresses");
			}
			SocketAddress sockAddr = ep.Serialize();
			port = (((int)sockAddr[2]) << 8) | sockAddr[3];
			addr = ((((uint)sockAddr[7]) << 24) | (((uint)sockAddr[6]) << 16) |
				(((uint)sockAddr[5]) << 8) | (uint)sockAddr[4]);
		}
开发者ID:bradparks,项目名称:DotNetAnywhere,代码行数:9,代码来源:Socket.cs

示例3: Connect

	// Connect to a remote end-point.
	public void Connect(EndPoint remoteEP)
			{
				// Validate the parameter.
				if(remoteEP == null)
				{
					throw new ArgumentNullException("remoteEP");
				}
				else if(remoteEP.AddressFamily != family)
				{
					throw new SocketException(Errno.EINVAL);
				}

				// Convert the end point into a sockaddr buffer.
				byte[] addr = remoteEP.Serialize().Array;

				// Lock down the socket object while we do the connect.
				lock(this)
				{
					// Bail out if the socket has been closed.
					if(handle == InvalidHandle)
					{
						throw new ObjectDisposedException
							(S._("Exception_Disposed"));
					}

					// Connect to the foreign location.
					if(!SocketMethods.Connect(handle, addr))
					{
						throw new SocketException(this.GetErrno());
					}
					connected = true;
					this.remoteEP = remoteEP;
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:35,代码来源:Socket.cs

示例4: Bind

	// Bind this socket to a specific end-point.
	public void Bind(EndPoint localEP)
			{
				// Validate the parameter.
				if(localEP == null)
				{
					throw new ArgumentNullException("localEP");
				}
				else if(localEP.AddressFamily != family)
				{
					throw new SocketException(Errno.EINVAL);
				}

				// Convert the end point into a sockaddr buffer.
				byte[] addr = localEP.Serialize().Array;

				// Lock down the socket object while we do the bind.
				lock(this)
				{
					// Bail out if the socket has been closed.
					if(handle == InvalidHandle)
					{
						throw new ObjectDisposedException
							(S._("Exception_Disposed"));
					}

					// Bind the address to the socket.
					if(!SocketMethods.Bind(handle, addr))
					{
						throw new SocketException(this.GetErrno());
					}

					// Record the local end point for later.
					this.localEP = localEP;
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:36,代码来源:Socket.cs

示例5: SendTo

	// Send data on this socket to a specific location.
	public int SendTo(byte[] buffer, int offset, int size,
					  SocketFlags socketFlags, EndPoint remoteEP)
			{
				int result;
				byte[] addr;

				// Validate the arguments.
				ValidateBuffer(buffer, offset, size);
				if(remoteEP == null)
				{
					throw new ArgumentNullException("remoteEP");
				}
				else if(remoteEP.AddressFamily != family)
				{
					throw new SocketException(Errno.EINVAL);
				}

				// Convert the end point into a sockaddr buffer.
				addr = remoteEP.Serialize().Array;

				// Perform the send operation.
				lock(this)
				{
					if(handle == InvalidHandle)
					{
						throw new ObjectDisposedException
							(S._("Exception_Disposed"));
					}
					result = SocketMethods.SendTo
						(handle, buffer, offset, size, (int)socketFlags, addr);
					if(result < 0)
					{
						throw new SocketException(this.GetErrno());
					}
					else
					{
						return result;
					}
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:41,代码来源:Socket.cs

示例6: ReceiveFrom

	// Receive data on this socket and record where it came from.
	public int ReceiveFrom(byte[] buffer, int offset, int size,
					       SocketFlags socketFlags, ref EndPoint remoteEP)
			{
				int result;
				byte[] addrReturn;

				// Validate the arguments.
				ValidateBuffer(buffer, offset, size);
				if(remoteEP == null)
				{
					throw new ArgumentNullException("remoteEP");
				}
				else if(remoteEP.AddressFamily != family)
				{
					throw new SocketException(Errno.EINVAL);
				}

				// Create a sockaddr buffer to write the address into.
				addrReturn = remoteEP.Serialize().Array;
				Array.Clear(addrReturn, 0, addrReturn.Length);

				// Perform the receive operation.
				lock(readLock)
				{
					if(handle == InvalidHandle)
					{
						throw new ObjectDisposedException
							(S._("Exception_Disposed"));
					}
					result = SocketMethods.ReceiveFrom
						(handle, buffer, offset, size,
						 (int)socketFlags, addrReturn);
					if(result < 0)
					{
						throw new SocketException(this.GetErrno());
					}
					else
					{
						remoteEP = remoteEP.Create
							(new SocketAddress(addrReturn));
						return result;
					}
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:45,代码来源:Socket.cs

示例7: OverlappedCallback

        } // OverlappedCallback()


        //
        // SetUnmanagedStructures -
        // Fills in Overlapped Structures used in an Async Overlapped Winsock call
        //   these calls are outside the runtime and are unmanaged code, so we need
        //   to prepare specific structures and ints that lie in unmanaged memory
        //   since the Overlapped calls can be Async
        //
        internal void SetUnmanagedStructures(
            byte[] buffer,
            int offset,
            int size,
            SocketFlags socketFlags,
            EndPoint remoteEP,
            bool pinRemoteEP ) {

                //
                // create the event handle
                //

                m_OverlappedEvent = new AutoResetEvent(false);

                //
                // fill in the overlapped structure with the event handle.
                //

                Marshal.WriteIntPtr(
                    m_UnmanagedBlob,
                    Win32.OverlappedhEventOffset,
                    m_OverlappedEvent.Handle );

            //
            // Fill in Buffer Array structure that will be used for our send/recv Buffer
            //
            m_WSABuffer = new WSABuffer();
            m_GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            m_WSABuffer.Length = size;
            m_WSABuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);

            //
            // fill in flags if we use it.
            //
            m_Flags = socketFlags;

            //
            // if needed fill end point
            //
            if (remoteEP != null) {
                m_SocketAddress = remoteEP.Serialize();
                if (pinRemoteEP) {
                    m_GCHandleSocketAddress = GCHandle.Alloc(m_SocketAddress.m_Buffer, GCHandleType.Pinned);
                    m_GCHandleSocketAddressSize = GCHandle.Alloc(m_SocketAddress.m_Size, GCHandleType.Pinned);                
                }
            }

        } // SetUnmanagedStructures()
开发者ID:ArildF,项目名称:masters,代码行数:58,代码来源:_overlappedasyncresult.cs

示例8: CallSerializeCheckDnsEndPoint

 private SocketAddress CallSerializeCheckDnsEndPoint(EndPoint remoteEP)
 {
     if (remoteEP is DnsEndPoint)
     {
         throw new ArgumentException("net_sockets_invalid_dnsendpoint");
     }
     return remoteEP.Serialize();
 }
开发者ID:BjkGkh,项目名称:R106,代码行数:8,代码来源:Socket.cs


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