import os
import sys
from django.core.wsgi import get_wsgi_application
import socketio
sio = socketio.Client()
print('Created socketio client')
@sio.event
def connect():
print('connected to server')
@sio.event
def disconnect():
print('disconnected from server')
sio.connect('http://localhost:8000/socket.io/')
sio.wait()
app_path = os.path.abspath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), os.pardir))
sys.path.append(os.path.join(app_path, 'myapp'))
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
application = get_wsgi_application()
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
application = application
Here is my wsgi.py file, I am not sure whether to use it here or not. When I start the server it throws
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\socketio\client.py", line 246, in connect
six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
File "<string>", line 3, in raise_from
socketio.exceptions.ConnectionError: Connection refused by the server
Am I missing out something else?
UPDATE 1
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001E926004C18>
Traceback (most recent call last):
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 140, in inner_run
handler = self.get_handler(*args, **options)
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 27, in get_handler
handler = super().get_handler(*args, **options)
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 65, in get_handler
return get_internal_wsgi_application()
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py", line 44, in get_internal_wsgi_application
return import_string(app_path)
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Programming\python\myapp\config\wsgi.py", line 34, in <module>
sio.connect('http://localhost:8000/socket.io/')
File "C:\Users\prabh\AppData\Local\Programs\Python\Python37\lib\site-packages\socketio\client.py", line 246, in connect
six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
File "<string>", line 3, in raise_from
UPDATE 2
socket.on('connect', function() {
console.log('CONNECTED');
socket.emit('on message', 'data');
});