You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def background_stuff():
""" Let's do it a bit cleaner """
while True:
time.sleep(1)
t = str(time.clock())
print(t)
socketio.emit('message', {'data': 'This is data', 'time': t}, namespace='/demo')
@app.route('/')
def index():
global thread
if thread is None:
thread = Thread(target=background_stuff)
thread.start()
return render_template('index4.html')
node js server works without problems
python socketio server also does not work!
Is there a solution?
python server debug message
(18940) accepted ('192.168.2.240', 49356)
192.168.2.240 - - [30/Nov/2018 00:26:19] "GET /socket.io/1/?transport=polling&b64=true HTTP/1.1" 200 364 0.000998
(18940) accepted ('192.168.2.240', 49357)
192.168.2.240 - - [30/Nov/2018 00:26:20] "GET /socket.io/1/websocket/?transport=websocket&b64=true&sid="11e20071782e4cfebf2 HTTP/1.1" 400 214 0.000000
Python Socket IO Server code
#!/usr/bin/env python
from flask import Flask, render_template, session, request
from flask_socketio import SocketIO, emit, join_room, leave_room,
close_room, rooms, disconnect
from threading import Thread
import time
async_mode = None
app = Flask(name)
#app.config['SECRET_KEY'] = 'hage!'
socketio = SocketIO(app, allow_upgrades=True, cookie=None)
#async_mode='gevent
#socketio = SocketIO(app)
thread = None
thread1 = None
count = 0
def background_stuff():
""" Let's do it a bit cleaner """
while True:
time.sleep(1)
t = str(time.clock())
print(t)
socketio.emit('message', {'data': 'This is data', 'time': t}, namespace='/demo')
def mServer ():
asyncio.get_event_loop().run_until_complete(test_coro())
asyncio.get_event_loop().run_forever()
@app.route('/')
def index():
global thread
if thread is None:
thread = Thread(target=background_stuff)
thread.start()
return render_template('index4.html')
@socketio.on('send_message_event', namespace='/demo')
def send_message_event(message):
session['receive_count'] = session.get('receive_count', 0) + 1
emit('my_response',
{'data': message['data'], 'count': session['receive_count']},
broadcast=True)
@socketio.on('message')
def handle_message(message):
print('received message geldi: ' + message)
@socketio.on('atime')
def handle_message(message):
print('received message geldi: ' + message)
@socketio.on('disconnect_request', namespace='/demo')
def disconnect_request():
session['receive_count'] = session.get('receive_count', 0) + 1
emit('my_response',
{'data': 'Disconnected!', 'count': session['receive_count']})
disconnect()
@socketio.on('connect')
def test_connect():
emit('my_response', {'data': 'Connected', 'count': 0})
@socketio.on('disconnect', namespace='/demo')
def test_disconnect():
print('Client disconnected', request.sid)
''' if thread1 is None:
thread1 = Thread(target= mServer)
thread1.start() '''
if name == 'main':
The text was updated successfully, but these errors were encountered: