小编Gal*_*erg的帖子

Python SocketServer适用于localhost,但不适用于服务器

下面是我目前使用的代码:

#! /usr/bin/python
print 'Content-type: application'
print '\n\n'

import SocketServer
import cgitb
cgitb.enable()

class MyTCPHandler(SocketServer.BaseRequestHandler):
    """
    The RequestHandler class for our server.

    It is instantiated once per connection to the server, and must
    override the handle() method to implement communication to the
    client.
    """

    def handle(self):
        # self.request is the TCP socket connected to the client
        self.data = self.request.recv(1024).strip()
        print "{} wrote:".format(self.client_address[0])
        print self.data
        # just send back the same data, but upper-cased
        self.request.sendall(self.data.upper())
        self.request.sendall('Data Received')

if __name__ == "__main__": …
Run Code Online (Sandbox Code Playgroud)

python sockets

4
推荐指数
2
解决办法
4719
查看次数

标签 统计

python ×1

sockets ×1