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


Python _socket.SOCK_STREAM属性代码示例

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


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

示例1: testSockName

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testSockName(self):
        # Testing getsockname()
        port = self._get_unused_port()
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        sock.bind(("0.0.0.0", port))
        name = sock.getsockname()
        # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
        # it reasonable to get the host's addr in addition to 0.0.0.0.
        # At least for eCos.  This is required for the S/390 to pass.
        try:
            my_ip_addr = socket.gethostbyname(socket.gethostname())
        except socket.error:
            # Probably name lookup wasn't set up right; skip this test
            self.skipTest('name lookup failure')
        self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
        self.assertEqual(name[1], port) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_socket.py

示例2: testSockName

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testSockName(self):
        # Testing getsockname()
        port = support.find_unused_port()
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        sock.bind(("0.0.0.0", port))
        name = sock.getsockname()
        # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
        # it reasonable to get the host's addr in addition to 0.0.0.0.
        # At least for eCos.  This is required for the S/390 to pass.
        try:
            my_ip_addr = socket.gethostbyname(socket.gethostname())
        except OSError:
            # Probably name lookup wasn't set up right; skip this test
            self.skipTest('name lookup failure')
        self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
        self.assertEqual(name[1], port) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_socket.py

示例3: test_dealloc_warn

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def test_dealloc_warn(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        r = repr(sock)
        with self.assertWarns(ResourceWarning) as cm:
            sock = None
            support.gc_collect()
        self.assertIn(r, str(cm.warning.args[0]))
        # An open socket file object gets dereferenced after the socket
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        f = sock.makefile('rb')
        r = repr(sock)
        sock = None
        support.gc_collect()
        with self.assertWarns(ResourceWarning):
            f = None
            support.gc_collect() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_socket.py

示例4: testTypes

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testTypes(self):
        families = [socket.AF_INET, socket.AF_INET6]
        types = [socket.SOCK_STREAM, socket.SOCK_DGRAM]
        for f in families:
            for t in types:
                try:
                    source = socket.socket(f, t)
                except OSError:
                    continue # This combination is not supported
                try:
                    data = source.share(os.getpid())
                    shared = socket.fromshare(data)
                    try:
                        self.compareSockets(source, shared)
                    finally:
                        shared.close()
                finally:
                    source.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_socket.py

示例5: test_errors

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def test_errors(self):
        with open(support.TESTFN, 'rb') as file:
            with socket.socket(type=socket.SOCK_DGRAM) as s:
                meth = self.meth_from_sock(s)
                self.assertRaisesRegex(
                    ValueError, "SOCK_STREAM", meth, file)
        with open(support.TESTFN, 'rt') as file:
            with socket.socket() as s:
                meth = self.meth_from_sock(s)
                self.assertRaisesRegex(
                    ValueError, "binary mode", meth, file)
        with open(support.TESTFN, 'rb') as file:
            with socket.socket() as s:
                meth = self.meth_from_sock(s)
                self.assertRaisesRegex(TypeError, "positive integer",
                                       meth, file, count='2')
                self.assertRaisesRegex(TypeError, "positive integer",
                                       meth, file, count=0.1)
                self.assertRaisesRegex(ValueError, "positive integer",
                                       meth, file, count=0)
                self.assertRaisesRegex(ValueError, "positive integer",
                                       meth, file, count=-1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_socket.py

示例6: try_address

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def try_address(host, port=0, family=socket.AF_INET):
    """Try to bind a socket on the given host:port and return True
    if that has been possible."""
    try:
        sock = socket.socket(family, socket.SOCK_STREAM)
        sock.bind((host, port))
    except (socket.error, socket.gaierror):
        return False
    else:
        sock.close()
        return True 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_socket.py

示例7: setUp

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def setUp(self):
        self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.port = test_support.bind_port(self.serv)
        self.serv.listen(1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_socket.py

示例8: clientSetUp

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def clientSetUp(self):
        self.cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_socket.py

示例9: test_csocket_repr

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def test_csocket_repr(self):
        s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
        try:
            expected = ('<socket object, fd=%s, family=%s, type=%s, protocol=%s>'
                        % (s.fileno(), s.family, s.type, s.proto))
            self.assertEqual(repr(s), expected)
        finally:
            s.close()
        expected = ('<socket object, fd=-1, family=%s, type=%s, protocol=%s>'
                    % (s.family, s.type, s.proto))
        self.assertEqual(repr(s), expected) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_socket.py

示例10: test_weakref

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def test_weakref(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        p = weakref.proxy(s)
        self.assertEqual(p.fileno(), s.fileno())
        s.close()
        s = None
        try:
            p.fileno()
        except ReferenceError:
            pass
        else:
            self.fail('Socket proxy still exists') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_socket.py

示例11: testGetSockOpt

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testGetSockOpt(self):
        # Testing getsockopt()
        # We know a socket should start without reuse==0
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
        self.assertFalse(reuse != 0, "initial mode is reuse") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py

示例12: testSetSockOpt

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testSetSockOpt(self):
        # Testing setsockopt()
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addCleanup(sock.close)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
        self.assertFalse(reuse == 0, "failed to set reuse mode") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py

示例13: testSendAfterClose

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testSendAfterClose(self):
        # testing send() after close() with timeout
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(1)
        sock.close()
        self.assertRaises(socket.error, sock.send, "spam") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_socket.py

示例14: testNewAttributes

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def testNewAttributes(self):
        # testing .family, .type and .protocol
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.assertEqual(sock.family, socket.AF_INET)
        self.assertEqual(sock.type, socket.SOCK_STREAM)
        self.assertEqual(sock.proto, 0)
        sock.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py

示例15: test_listen_backlog

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import SOCK_STREAM [as 别名]
def test_listen_backlog(self):
        for backlog in 0, -1:
            srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            srv.bind((HOST, 0))
            srv.listen(backlog)
            srv.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_socket.py


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