如何将数据发送到客户端?

时间:2012-03-04 14:48:48

标签: python sockets socketserver

from BaseHTTPServer import HTTPServer
from CGIHTTPServer  import CGIHTTPRequestHandler
import socket,ssl
import time
import Config

class StartHTTPServer:
    '''Web server to serve out map image and provide cgi'''


    def __init__(self):
        # Start HTTP Server. Port and address defined in Config.py
        srvraddr = ("", Config.HTTP_PORT)                     # my hostname, portnumber
        srvrobj  = HTTPServer(srvraddr, CGIHTTPRequestHandler)

        srvrobj.socket = ssl.wrap_socket(srvrobj.socket,server_side=True,
                                    certfile="c:\users\shuen\desktop\servertryout 23022012\serverCert.crt",
                                    keyfile="c:\users\shuen\desktop\servertryout 23022012\privateKey.key",
                                    ssl_version=ssl.PROTOCOL_TLSv1,
                                    do_handshake_on_connect=True)

        print srvrobj.socket.cipher() 
        print srvrobj.socket.getsockname()
        print "HTTP server running at IP Address %s port %s." % (Config.HTTP_ADDRESS, Config.HTTP_PORT)
        srvrobj.serve_forever()                              # run as perpetual demon

        srvrobj.socket.accept()
        message='hello from server.<EOF>'
        srvrobj.socket.send(message)

我尝试使用普通套接字发送数据,这有效。但是,我正在使用的代码是使用socketServer,无法更改。我找不到任何将数据发送到服务器的示例。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

如果您真的无法更改服务器软件,则必须使用包装器,例如: G。 openssl s_server