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

python socketio server also does not work! #61

Open
bulentkusva opened this issue Nov 29, 2018 · 0 comments
Open

python socketio server also does not work! #61

bulentkusva opened this issue Nov 29, 2018 · 0 comments

Comments

@bulentkusva
Copy link

bulentkusva commented Nov 29, 2018

image

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':

socketio.run(app, host='0.0.0.0', port=3000, debug=True)
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

1 participant