示例#1
0
 public static extern Int32 WSAAddressToString(ref SockAddrIn lpsaAddress, UInt32 dwAddressLength,
     IntPtr lpProtocolInfo, System.Text.StringBuilder lpszAddressString, ref UInt32 lpdwAddressStringLength);
示例#2
0
 public static extern Int32 WSAStringToAddress(String AddressString, AddressFamilyInt AddressFamily,
     IntPtr lpProtocolInfo, ref SockAddrIn pAddr, ref Int32 lpAddressLength);
示例#3
0
 public static extern Int32 connect(IntPtr s, ref SockAddrIn name, Int32 namelen);
示例#4
0
 public static extern IntPtr accept(IntPtr s, ref SockAddrIn addr, ref Int32 addrlen);
示例#5
0
 public static extern Int32 bind(IntPtr s, ref SockAddrIn name, Int32 namelen);
示例#6
0
        /// <summary>
        /// TODO: Update summary.
        /// </summary>
        public static SockAddrIn FromString(String host, Int32 port, AddressFamilyInt addressFamily)
        {
            SockAddrIn sockaddr = new SockAddrIn();
            Int32 lpAddressLength = Marshal.SizeOf(sockaddr);

            Wsa.Init();
            if(WinSock2.WSAStringToAddress(host + ":" + port, addressFamily,
                IntPtr.Zero, ref sockaddr, ref lpAddressLength) == WinSock2.SocketError)
            {
                throw new Win32Exception();
            }

            return sockaddr;
        }
示例#7
0
 /// <summary>
 /// Creates a new <see cref="Socket"/> for a newly created connection.
 /// </summary>
 /// <returns>
 /// Type: <see cref="yourmt.Sockets.Socket"/>
 /// A <see cref="Socket"/> for a newly created connection.
 /// </returns>
 public Socket Accept()
 {
     SockAddrIn sai = new SockAddrIn();
     Int32 len = Marshal.SizeOf(sai);
     IntPtr client = WinSock2.accept(Handle, ref sai, ref len);
     if(client == WinSock2.InvalidSocket)
         throw new Win32Exception();
     return new Socket(client, false, true, AddressFamily, SocketType, ProtocolType, sai.Host, sai.Port);
 }