<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中将消息从客户端发送到服务器

        时间:2024-04-20

        <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中将消息从客户端发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:500 App Engine(Google Cloud)中我的Django应用程序出现服务器错误 下一篇:在终端运行python文件时,返回的命令不会执行吗?

                  相关文章

                    <bdo id='6vDUi'></bdo><ul id='6vDUi'></ul>

                1. <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>
                2. <tfoot id='6vDUi'></tfoot>

                    1. <small id='6vDUi'></small><noframes id='6vDUi'>