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

How to close/terminate the socket connection? #1

Open
andyprasetya opened this issue Mar 19, 2018 · 0 comments
Open

How to close/terminate the socket connection? #1

andyprasetya opened this issue Mar 19, 2018 · 0 comments

Comments

@andyprasetya
Copy link

andyprasetya commented Mar 19, 2018

Hello, I tried to implement setInterval in the block ws.onmessage with the following code:

ws.on('message', function incoming(message) {
	console.log('received: %s', message);
	setInterval(function(){
		ws.send('message from server at: ' + new Date());
	},10*1000);
	connectedUsers.push(message);
});

And this was triggered by the client's code:

function socket_data () {
	wsocket = new WebSocket('ws://localhost:3000/socketdata');
	wsocket.onopen = function () {
		console.log('client is trying to open websocket for realtime data...');
		wsocket.send('request_data');
	}
	wsocket.onmessage = function (evt) {
		console.log(evt.data);
	}
}

Now, how to implement close/terminate the socket connection?

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