문제

I've got a simple server. It works if I do a normal socket, but if I try to use a unix socket, I don't think it's working.

Here is the server:

from tornado.httpserver import HTTPServer
import tornado.ioloop
from tornado.netutil import bind_unix_socket
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    server = HTTPServer(application)
    unix_socket = bind_unix_socket('/tmp/foo.sock')
    server.add_socket(unix_socket)
    tornado.ioloop.IOLoop.instance().start()

Here is how I'm testing:

~  socat - UNIX-CONNECT:/tmp/foo.sock
GET / HTTP/1.1
HOST: foobar.com
*hit enter a few times to complete http call*

The server doesn't give any response.

Any idea what I'm doing wrong?

도움이 되었습니까?

해결책

You're sending \n instead of \r\n. You can use socat's "crnl" option to make it work more like telnet:

socat - unix-connect:/tmp/foo.sock,crnl
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top