I'm new to socket io and I'm quite confused because I receive duplicate messages from the server. I'm using flask-socketio on the server side.
Here's the server side code:
class StdOutListener1(StreamListener):
def on_data(self, data):
data = json.loads(data)
socketio.emit('streamTweets1',{"data": data},namespace='/tweet')
@socketio.on("connect", namespace="/tweet")
def connectServer():
print("Client connected")
socketio.emit("connected", namespace="/tweet")
@socketio.on('startTweets1', namespace='/tweet')
def tweetStreaming1():
stream_1 = Stream(auth_1, l1)
stream_1.filter(track=search_list_1)
stream_1.filter(track=search_list_1)
will call the on_data
function in StdOutListener1
class.
my client side code is:
socket = io.connect("http://" + document.domain + ":" + location.port + "/tweet");
// listen to the event 'connected'
socket.on("connected", function(data) {
console.log("listening connected...");
socket.emit("startTweets1");
});
socket.on("streamTweets1", function(data){
console.log(data)
});
every time after I refresh my client side page, I will get duplicate results.
Also, I'm not sure how to stop or disconnect. I tried to use control + c to for the server to stop, but it seems it will continue running. how do I correctly stop the server and disconnect?