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

        <legend id='qjNDZ'><style id='qjNDZ'><dir id='qjNDZ'><q id='qjNDZ'></q></dir></style></legend>
      1. <i id='qjNDZ'><tr id='qjNDZ'><dt id='qjNDZ'><q id='qjNDZ'><span id='qjNDZ'><b id='qjNDZ'><form id='qjNDZ'><ins id='qjNDZ'></ins><ul id='qjNDZ'></ul><sub id='qjNDZ'></sub></form><legend id='qjNDZ'></legend><bdo id='qjNDZ'><pre id='qjNDZ'><center id='qjNDZ'></center></pre></bdo></b><th id='qjNDZ'></th></span></q></dt></tr></i><div id='qjNDZ'><tfoot id='qjNDZ'></tfoot><dl id='qjNDZ'><fieldset id='qjNDZ'></fieldset></dl></div>
      2. <tfoot id='qjNDZ'></tfoot>
          <bdo id='qjNDZ'></bdo><ul id='qjNDZ'></ul>

        如何在python中将消息从客户端发送到服务器

        How to send a message from client to server in python(如何在python中将消息从客户端发送到服务器)

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

            <tbody id='pbeRo'></tbody>

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

                  本文介绍了如何在python中将消息从客户端发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在阅读Python2.7.10中具有客户端和服务器的两个程序。如何修改这些程序以将邮件从客户端发送到服务器?

                  server.py:

                  #!/usr/bin/python           # This is server.py file
                  
                  import socket               # Import socket module
                  
                  s = socket.socket()         # Create a socket object
                  host = socket.gethostname() # Get local machine name
                  port = 12345                # Reserve a port for your service.
                  s.bind((host, port))        # Bind to the port
                  
                  s.listen(5)                 # Now wait for client connection.
                  while True:
                     c, addr = s.accept()     # Establish connection with client.
                     print 'Got connection from', addr
                     c.send('Thank you for connecting')
                     c.close()                # Close the connection
                  

                  client.py:

                  #!/usr/bin/python           # This is client.py file
                  
                  import socket               # Import socket module
                  
                  s = socket.socket()         # Create a socket object
                  host = socket.gethostname() # Get local machine name
                  port = 80              # Reserve a port for your service.
                  
                  s.connect((host, port))
                  print s.recv(1024)
                  s.close                     # Close the socket when done
                  

                  推荐答案

                  套接字是双向的。所以连接后,服务器和客户端没有区别,只有流的两端:

                  import socket               # Import socket module
                  
                  s = socket.socket()         # Create a socket object
                  s.bind(('0.0.0.0', 12345))        # Bind to the port
                  
                  s.listen(5)                 # Now wait for client connection.
                  while True:
                     c, addr = s.accept()     # Establish connection with client.
                     print 'Got connection from', addr
                     print c.recv(1024)
                     c.close()                # Close the connection
                  

                  和客户端:

                  import socket               # Import socket module
                  
                  s = socket.socket()         # Create a socket object
                  s.connect(('localhost', 12345))
                  s.sendall('Here I am!')
                  s.close()                     # Close the socket when done
                  

                  这篇关于如何在python中将消息从客户端发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                      <bdo id='6vDUi'></bdo><ul id='6vDUi'></ul>

                    • <legend id='6vDUi'><style id='6vDUi'><dir id='6vDUi'><q id='6vDUi'></q></dir></style></legend>
                      <i id='6vDUi'><tr id='6vDUi'><dt id='6vDUi'><q id='6vDUi'><span id='6vDUi'><b id='6vDUi'><form id='6vDUi'><ins id='6vDUi'></ins><ul id='6vDUi'></ul><sub id='6vDUi'></sub></form><legend id='6vDUi'></legend><bdo id='6vDUi'><pre id='6vDUi'><center id='6vDUi'></center></pre></bdo></b><th id='6vDUi'></th></span></q></dt></tr></i><div id='6vDUi'><tfoot id='6vDUi'></tfoot><dl id='6vDUi'><fieldset id='6vDUi'></fieldset></dl></div>
                      <tfoot id='6vDUi'></tfoot>
                        <tbody id='6vDUi'></tbody>

                          • <small id='6vDUi'></small><noframes id='6vDUi'>