V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sbmzhcn
V2EX  ›  Python

SocketServer self.request.sendall 与原生 socket.send 问题

  •  
  •   sbmzhcn · 2014-12-11 13:57:33 +08:00 · 2590 次点击
    这是一个创建于 3438 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class Server(ThreadingMixIn, TCPServer): pass

    server = Server(('', 8089), ThreadedTCPRequestHandler)
    server.serve_forever()

    class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):

    def handle(self):
    data = self.request.recv(1024)
    self.request.sendall(b'\x33\x34\x35')

    上面的self.request.sendall(b'\x33\x34\x35') 与

    connection, address = sock.accept()
    connection.send(b'\x33\x34\x35')

    有什么不同,为什么我用下面的socket.send是没有问题的,服务器能识别我发送的数据,但是最上面的那代码发送的数据就无法识别。为什么?

    都是发送一段16进制的代码,为什么一个可以,一个不可以,想请教是什么,搞了一天了也没有解决!!!
    ==
    sendall ,send, 都试了,一样的。
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2987 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:31 · PVG 08:31 · LAX 17:31 · JFK 20:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.