Answer the question
In order to leave comments, you need to log in
How to setup socket.io client for django channels?
Here is the code on the client:
const lat = 132;
const lng = 132;
const server = 'wss://example.ru';
const login = '123';
const pass = 'qwerty123';
const socket = io.connect(
server,
{
transports: ["websocket"],
path: "/ws/test/"+login+"/"+pass+"/"
}
);
class TestConsumer(WebsocketConsumer):
""" Соединие с приложением """
def connect(self):
user_login = self.scope['url_route']['kwargs']['user_id']
user_password = self.scope['url_route']['kwargs']['password']
print(user_login)
print(user_password)
print(self.scope)
if user_password == 'qwerty123':
print('Пароль верен')
self.accept()
self.send(text_data="2000")
else:
print('Пароль неверен')
self.close()
def receive(self,text_data=None, bytes_data=None):
print(text_data)
print(bytes_data)
def disconnect(self, close_code):
# print('disconnect')
pass
var url = 'wss://example.ru/ws/test/';
var user_login = '123';
var user_password = 'qwerty123';
var chatSocket = new WebSocket(
url+user_login+'/'+user_password+'/'
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question