Exemple #1
0
        private void Start(ushort port, byte address1, byte address2, byte address3, byte address4)
        {
            // BIND
            in_addr inAddress = new in_addr();
            inAddress.s_b1 = address1;
            inAddress.s_b2 = address2;
            inAddress.s_b3 = address3;
            inAddress.s_b4 = address4;

            sockaddr_in sa = new sockaddr_in();
            sa.sin_family = ADDRESS_FAMILIES.AF_INET;
            sa.sin_port = SocketImports.htons(port);
            sa.sin_addr = inAddress;

            int result;
            unsafe
            {
                var size = sizeof(sockaddr_in);
                result = SocketImports.bind(_handle, ref sa, size);
            }
            if (result == SocketImports.SOCKET_ERROR)
            {
                SocketImports.WSACleanup();
                throw new Exception("bind failed");
            }

            // LISTEN
            result = SocketImports.listen(_handle, 10);
            if (result == SocketImports.SOCKET_ERROR)
            {
                SocketImports.WSACleanup();
                throw new Exception("listen failed");
            }
        }
Exemple #2
0
 public static extern int bind(IntPtr s, ref sockaddr_in name, int namelen);
Exemple #3
0
 public static extern int bind(IntPtr s, ref sockaddr_in name, int namelen);