Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client not finding Socket.IO server #55

Closed
alexanderdushkin opened this issue Nov 8, 2016 · 5 comments
Closed

Client not finding Socket.IO server #55

alexanderdushkin opened this issue Nov 8, 2016 · 5 comments

Comments

@alexanderdushkin
Copy link

I'm using Flask with uWSGI and NGINX, having set up the Socket.IO server as sio = socketio.Server(async_mode='gevent_uwsgi', logger=True). The whole thing is running in a Docker container which listens on localhost port 3536.

On the client side, I have JS which sends socket requests to Socket.IO. On all requests Chrome shows 404 NOT FOUND, while server logs don't show nothing at all.

For instance, I have this thing on server side:

@sio.on('process_registration', namespace='/regauth')
def process_registration(sid, message):
    <...>

And this on the client:

<script type="text/javascript">
      /* global io, grecaptcha, $ */
      namespace = "/regauth";
      var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);

      $('#register-send_btn').click(function() {
           var username = $('#register-username').val(),
               pwd = $('#register-pwd').val(),
               pwd_confirm = $('#register-pwd_confirm').val(),
               email = $('#register-email').val(),
               grecaptcha_response = $('#register-grecaptcha_response').val();

           socket.emit("process_registration", {
               uname: username,
               password: pwd,
               password2: pwd_confirm,
               email: email,
               recaptcha_response: grecaptcha_response
           });
    });
</script>

The error I'm getting is:

socket.io.js:4196 GET http://127.0.0.1:3536/socket.io/?EIO=3&transport=polling&t=LX4DrIW 404 (NOT FOUND)

It seems either that the browser ignores the io.connect('http://' + document.domain + ':' + location.port + namespace); line because requests are still sent to /socket.io, or the server is not listening. Help me, please :)

@miguelgrinberg
Copy link
Owner

How are you running the server inside your docker container?

@alexanderdushkin
Copy link
Author

alexanderdushkin commented Nov 8, 2016

nginx
uwsgi --master \
      --processes 5 \
      --socket /sockets/site.sock \
      --gevent 1000 \
      --http-websockets \
      --chmod-socket=660 \
      --die-on-term \
      --wsgi-file /app/wsgi.py

And inside the app:

sio = socketio.Server(async_mode='gevent_uwsgi', logger=True)
application = Flask(__name__)

@miguelgrinberg
Copy link
Owner

First of all, you can't use more than one server process unless you also use a message queue. I don't think that's the reason for the 404s, but keep that in mind once you resolve this issue.

I would switch to the configuration that I recommend in the documentation (here). That's something that I tested, so start from there. Main difference is that I did not use a unix socket.

@alexanderdushkin
Copy link
Author

Sorry, what do you mean by using more than one server process?

Thanks, I will try using that configuration and a couple of other ones if it don't work.

@miguelgrinberg
Copy link
Owner

I mean this option will not work: --processes 5. It needs to be 1, or else you need to do the message queue configuration for the 5 processes to be able to talk among themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants