<i id='qrunB'><tr id='qrunB'><dt id='qrunB'><q id='qrunB'><span id='qrunB'><b id='qrunB'><form id='qrunB'><ins id='qrunB'></ins><ul id='qrunB'></ul><sub id='qrunB'></sub></form><legend id='qrunB'></legend><bdo id='qrunB'><pre id='qrunB'><center id='qrunB'></center></pre></bdo></b><th id='qrunB'></th></span></q></dt></tr></i><div id='qrunB'><tfoot id='qrunB'></tfoot><dl id='qrunB'><fieldset id='qrunB'></fieldset></dl></div>
  • <small id='qrunB'></small><noframes id='qrunB'>

      <bdo id='qrunB'></bdo><ul id='qrunB'></ul>
    <legend id='qrunB'><style id='qrunB'><dir id='qrunB'><q id='qrunB'></q></dir></style></legend>
        <tfoot id='qrunB'></tfoot>

      1. python中Socket.accept()的返回值是什么

        What#39;s the return value of Socket.accept() in python(python中Socket.accept()的返回值是什么)
        <legend id='YyHwB'><style id='YyHwB'><dir id='YyHwB'><q id='YyHwB'></q></dir></style></legend>
          <bdo id='YyHwB'></bdo><ul id='YyHwB'></ul>

            <tbody id='YyHwB'></tbody>
          <tfoot id='YyHwB'></tfoot>

                <small id='YyHwB'></small><noframes id='YyHwB'>

                  <i id='YyHwB'><tr id='YyHwB'><dt id='YyHwB'><q id='YyHwB'><span id='YyHwB'><b id='YyHwB'><form id='YyHwB'><ins id='YyHwB'></ins><ul id='YyHwB'></ul><sub id='YyHwB'></sub></form><legend id='YyHwB'></legend><bdo id='YyHwB'><pre id='YyHwB'><center id='YyHwB'></center></pre></bdo></b><th id='YyHwB'></th></span></q></dt></tr></i><div id='YyHwB'><tfoot id='YyHwB'></tfoot><dl id='YyHwB'><fieldset id='YyHwB'></fieldset></dl></div>
                  本文介绍了python中Socket.accept()的返回值是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我用python中的socket模块做了一个简单的服务器和一个简单的客户端.

                  I made a simple server and a simple client with socket module in python.

                  服务器:

                  # server.py
                  import socket
                  
                  s = socket.socket()
                  host = socket.gethostname()
                  port = 1234
                  s.bind((host, port))
                  
                  s.listen(5)
                  
                  while True:
                      c, addr = s.accept()
                      print 'Got connection from', addr
                      c.send('Thank you for your connecting')
                      c.close()
                  

                  和客户:

                  #client.py
                  import socket
                  
                  s = socket.socket()
                  
                  host = socket.socket()
                  port = 1234
                  
                  s.connect((host, port))
                  print s.recv(1024)
                  

                  我启动了服务器,然后启动了 4 个客户端,并在服务器的控制台中得到如下输出:

                  I started the server and then started 4 clients and got output in server's console as below:

                  Got connection from ('192.168.0.99', 49170)
                  Got connection from ('192.168.0.99', 49171)
                  Got connection from ('192.168.0.99', 49172)
                  Got connection from ('192.168.0.99', 49173)
                  

                  元组的第二部分是什么?

                  what is the second part in the tuple?

                  推荐答案

                  来自 socket 文档:

                  From the socket documentation:

                  AF_INET 地址族使用一对 (host, port),其中 host 是一个字符串,表示 Internet 域表示法中的主机名,如daring.cwi.nl"或 IPv4 地址,如100.50.200.5",端口是一个整数.

                  A pair (host, port) is used for the AF_INET address family, where host is a string representing either a hostname in Internet domain notation like 'daring.cwi.nl' or an IPv4 address like '100.50.200.5', and port is an integer.

                  所以第二个值是客户端用于连接的端口号.当建立 TCP/IP 连接时,客户端选择一个传出端口号与服务器通信;服务器返回的数据包将被寻址到该端口号.

                  So the second value is the port number used by the client side for the connection. When a TCP/IP connection is established, the client picks an outgoing port number to communicate with the server; the server return packets are to be addressed to that port number.

                  这篇关于python中Socket.accept()的返回值是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <i id='qAAjd'><tr id='qAAjd'><dt id='qAAjd'><q id='qAAjd'><span id='qAAjd'><b id='qAAjd'><form id='qAAjd'><ins id='qAAjd'></ins><ul id='qAAjd'></ul><sub id='qAAjd'></sub></form><legend id='qAAjd'></legend><bdo id='qAAjd'><pre id='qAAjd'><center id='qAAjd'></center></pre></bdo></b><th id='qAAjd'></th></span></q></dt></tr></i><div id='qAAjd'><tfoot id='qAAjd'></tfoot><dl id='qAAjd'><fieldset id='qAAjd'></fieldset></dl></div>
                  • <bdo id='qAAjd'></bdo><ul id='qAAjd'></ul>

                      <legend id='qAAjd'><style id='qAAjd'><dir id='qAAjd'><q id='qAAjd'></q></dir></style></legend>
                          <tbody id='qAAjd'></tbody>

                          <small id='qAAjd'></small><noframes id='qAAjd'>

                            <tfoot id='qAAjd'></tfoot>